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

本人開發的開發者技術變現資源彙集地,你們支持下,下面是網址android

https://www.baiydu.comobjective-c

 

 

該控件的主要實現思路是用的objective-c中的自定義控件思路,主視圖中放子視圖網絡

效果圖this

 (窗體調用代碼)
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多萬,各類當前熱門的網絡手機獎勵紅包所有集成,另外還有熱門電影和淘寶高額優惠券!很適合各種型的用戶。spa

  

相關文章
相關標籤/搜索