C#Winform VScrollBar+Pannel自定义列表控件(原)

时间:2023-01-10 17:54:55

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

https://www.baiydu.com

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

效果图

C#Winform VScrollBar+Pannel自定义列表控件(原)

 (窗体调用代码)
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自定义列表控件(原)