本人开发的开发者技术变现资源聚集地,大家支持下,下面是网址

https://www.baiydu.com

该控件的主要实现思路是用的objective-c中的自定义控件思路,主视图中放子视图

效果图

 (窗体调用代码)
public partial class Form1 : RibbonForm
{
List<Panel> arrayPanel = new List<Panel>();
List<Panel> arrayPanel1 = new List<Panel>();
List<LabelControl> detailButtonArray = new List<LabelControl>();
public Form1()
{ for (int i = 0; i < 30; i++)
{ string NoticeTitle = "自定义ScrollbarList控件";
string PublishData = "2014-6-3";
Panel tempPanel = new Panel();
tempPanel.Height = 25;
tempPanel.Width = 330;
LabelControl noticeTitleLabel = new LabelControl();
noticeTitleLabel.Text = NoticeTitle;
noticeTitleLabel.ForeColor = Color.FromArgb(22, 66, 139);
noticeTitleLabel.Location = new Point(5, 5);
tempPanel.Controls.Add(noticeTitleLabel );
LabelControl noticePublishDataLabel = new LabelControl();
noticePublishDataLabel.ForeColor = Color.FromArgb(22, 66, 139);
noticePublishDataLabel.Text = PublishData;
noticePublishDataLabel.Location = new Point(200, 5);
tempPanel.Controls.Add(noticePublishDataLabel);
LabelControl detialInfoButton = new LabelControl();
detialInfoButton.Location = new Point(290,5);
//detialInfoButton.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Simple;
detialInfoButton.Text = "查看";
detialInfoButton.ForeColor = Color.FromArgb(22, 66, 139);
detialInfoButton.Click += pannelClick;
detailButtonArray.Add(detialInfoButton);
tempPanel.Controls.Add(detialInfoButton);
tempPanel.Location = new Point(5, i * 25 + i * 5);
arrayPanel.Add(tempPanel);
} for (int i = 0; i < 10; i++)
{ string NoticeTitle = "自定义ScrollbarList控件";
string PublishData = "2014-6-3";
Panel tempPanel = new Panel();
tempPanel.Height = 25;
tempPanel.Width = 330;
LabelControl noticeTitleLabel = new LabelControl();
noticeTitleLabel.Text = NoticeTitle;
noticeTitleLabel.ForeColor = Color.FromArgb(22, 66, 139);
noticeTitleLabel.Location = new Point(5, 5);
tempPanel.Controls.Add(noticeTitleLabel);
LabelControl noticePublishDataLabel = new LabelControl();
noticePublishDataLabel.ForeColor = Color.FromArgb(22, 66, 139);
noticePublishDataLabel.Text = PublishData;
noticePublishDataLabel.Location = new Point(200, 5);
tempPanel.Controls.Add(noticePublishDataLabel);
LabelControl detialInfoButton = new LabelControl();
detialInfoButton.Location = new Point(290, 5);
//detialInfoButton.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Simple;
detialInfoButton.Text = "查看";
detialInfoButton.ForeColor = Color.FromArgb(22, 66, 139);
detialInfoButton.Click += pannelClick;
detailButtonArray.Add(detialInfoButton);
tempPanel.Controls.Add(detialInfoButton);
tempPanel.Location = new Point(5, i * 25 + i * 5);
arrayPanel1.Add(tempPanel);
}
InitializeComponent();
InitSkinGallery();
InitGrid(); this.noticeControl1.tempMasterPanel = arrayPanel;
this.noticeControl1.bindSource();
this.noticeControl1.NoticeTitle = "最新供应信息";
this.noticeControl1.setTitle(); this.noticeControl2.tempMasterPanel = arrayPanel1;
this.noticeControl2.bindSource();
this.noticeControl2.NoticeTitle = "最新求购信息";
this.noticeControl2.setTitle(); }
/// <summary>
/// 列表中最后一列按钮绑定的CLICK事件(为了好看一点,这按钮用的是LABEL标签)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pannelClick(object sender, EventArgs e)
{
foreach (LabelControl contronl in detailButtonArray)
{
if (contronl == sender)
{
(这个弹出框也是用WINFORM窗体重写过的,就不发布出来了)
CustomContronl.AlertForm AlertForm = new CustomContronl.AlertForm("hihihi!!!"); AlertForm.ShowDialog();
}
}
}

  

(自定义控件代码)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections; namespace DXApplication14.CustomContronl
{
public partial class noticeControl : UserControl
{
VScrollBar vScrollBar1 = new VScrollBar();
Panel contentPannel = new Panel();
public string NoticeTitle { get; set; }
public List<Panel> tempMasterPanel { get; set; } public int CrrentValue = 0;
int changeValue = 0;
public noticeControl()
{
vScrollBar1.Scroll += new ScrollEventHandler(
this.vScrollBar1_Scroll);
vScrollBar1.ValueChanged += new EventHandler(
this.vScrollBar1_ValueChanged);
InitializeComponent();
vScrollBar1.Location = new Point(290, 25);
vScrollBar1.Height = 300;
Controls.Add(vScrollBar1); } public void setTitle()
{
this.labelControl1.Text = NoticeTitle;
}

private void vScrollBar1_ValueChanged(Object sender,
EventArgs e)
{ if (CrrentValue == vScrollBar1.Value)
{
return;
} else
{ changeValue = CrrentValue - vScrollBar1.Value; if (changeValue > 0)
{ foreach (Panel pannel in tempMasterPanel)
{ pannel.Location = new Point(pannel.Location.X, pannel.Location.Y - (changeValue * 25 + changeValue * 5)*-1);
} }
else
{
foreach (Panel pannel in tempMasterPanel)
{ pannel.Location = new Point(pannel.Location.X, pannel.Location.Y + (changeValue * 25 + changeValue * 5));
} } CrrentValue = vScrollBar1.Value;
}
} private void vScrollBar1_Scroll(Object sender,
ScrollEventArgs e)
{ } //给scrollbarList绑定数据的方法
public void bindSource()
{
vScrollBar1.Maximum = tempMasterPanel.Count + 10;
contentPannel.Width = this.Width - 2;
contentPannel.Height = tempMasterPanel.Count * 25 + tempMasterPanel.Count * 5;
contentPannel.Location = new Point(1, 25);
foreach (Panel pannel in tempMasterPanel)
{
contentPannel.Controls.Add(pannel);
} this.Controls.Add(contentPannel);
} }
}

  

本人创业做的一款androidApp, 下载量已经有2000多万,各种当前热门的网络手机奖励红包全部集成,另外还有热门电影和淘宝高额优惠券!很适合各类型的用户。

 

C#Winform VScrollBar+Pannel自定义列表控件(原)的更多相关文章

  1. 在Winform界面使用自定义用户控件及TabelPanel和StackPanel布局控件

    在很多时候,我们做一些非常规化的界面的时候,往往需要创建一些用户控件,在其中绘制好一些基础的界面块,作为后续重复使用的一个单元,用户控件同时也可以封装处理一些简单的逻辑.在开发Winform各种类型项 ...

  2. 【winform程序】自定义webrowser控件调用IE的版本

    修改注册表: bit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROW ...

  3. WinForm中使用自定义Tooltip控件

    private ToolTip tooltipCtr; 构造函数中: 隐藏默认的Tooltip:this.ShowCellToolTips = false; this.tooltipCtr = new ...

  4. .NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)

    说说WebForm: 数据列表控件: WebForm 下的列表绑定控件基本就是GridView.DataList.Repeater:当然还有其它DropDownList.ListBox等. 它们的共同 ...

  5. WPF自定义控件与样式(7)-列表控件DataGrid与ListView自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Dat ...

  6. Android自定义标签列表控件LabelsView解析

    版权声明:本文为博主原创文章,未经博主允许不得转载. 无论是在移动端的App,还是在前端的网页,我们经常会看到下面这种标签的列表效果:   标签从左到右摆放,一行显示不下时自动换行.这样的效果用And ...

  7. 【转】WPF自定义控件与样式(7)-列表控件DataGrid与ListView自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等. 本文主要内容: DataGrid自定义样式: ListView自定义样式: 二.Dat ...

  8. (转载)Android自定义标签列表控件LabelsView解析

    Android自定义标签列表控件LabelsView解析 作者 donkingliang 关注 2017.03.15 20:59* 字数 759 阅读 406评论 0喜欢 3 无论是在移动端的App, ...

  9. Winform自定义键盘控件开发及使用

    最近有学员提出项目中要使用键盘控件,系统自带的osk.exe不好用,于是就有了下面的内容: 首先是进行自定义键盘控件的开发,其实核心大家都知道,就是利用SendKeys.Send发送相应 的字符,但是 ...

随机推荐

  1. Redis总结笔记(二):C#连接Redis简单例子

    转载于:http://www.itxuexiwang.com/a/shujukujishu/redis/2016/0216/113.html?1455860686 注:C#在调用Redis是不要使用S ...

  2. Nodejs·进程

    之前对这部分的内容很感兴趣,没想到读起来有点晦涩,还是因为对服务器的知识不是很了解. 说道服务器一般人都会想到tomcat或者Jboss或者weblogic,现在流行起来的Node总让人不太放心,JS ...

  3. fir.im Weekly - 这是一份强大的 SwiftGuide

    大新闻!Apple 10 亿美元融资滴滴!库克大叔对中国 iOS 开发者表达了高度认可,同时也传出 iOS 10 将内置滴滴 App 的消息.想像下,某个加班的深夜飙完代码,最性感的事情莫过于:「Si ...

  4. html_01之基础标签

    1.嵌套规则:①行内不能嵌套块:②p不能嵌套块:③非布局元素不要嵌套div: 2.标准属性:①id:定义元素唯一名称(a.布局时用:b.JS用):②title:鼠标移入时提示的文字:③class:定义 ...

  5. 为什么说基于TCP的移动端IM仍然需要心跳保活?

    1.前言 很多人认为,TCP协议自身先天就有KeepAlive机制,为何基于它的通讯链接,仍然需要在应用层实现额外的心跳保活?本文将从移动端IM实践的角度告诉你,即使使用的是TCP协议,应用层的心跳保 ...

  6. java基础,继承类题目:编写一个Java应用程序,该程序包括3个类:Monkey类、People类和主类 E

    21.编写一个Java应用程序,该程序包括3个类:Monkey类.People类和主类 E.要求: (1) Monkey类中有个构造方法:Monkey (String s),并且有个public vo ...

  7. 【译】采用MVC模式创建一个简单的javascript App

    原文标题:Build A Simple Javascript App The MVC Way 作者:joshcrawmer4 翻译人:huansky 初次翻译,翻译的不好,还请见谅 JavaScrip ...

  8. 初次使用IDEA的相关技巧

    前言:由于初次使用IDEA,所以很多配置都不是非常熟悉,经过一下午慢慢熟悉和同事的帮助,终于有所斩获,现在我把这个总结写出来,希望能够帮助初次使用的java工程师. 1:下载和安装 下载地址:http ...

  9. 纯CSS制作水平垂直居中“十字架”

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. (扩展欧几里德算法)zzuoj 10402: C.机器人

    10402: C.机器人 Description Dr. Kong 设计的机器人卡尔非常活泼,既能原地蹦,又能跳远.由于受软硬件设计所限,机器人卡尔只能定点跳远.若机器人站在(X,Y)位置,它可以原地 ...