C# winform自定义翻页控件详解自定义翻页控件详解
主要为大家详细介绍了C# winform自定义翻页控件的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
C# winform中自定义的翻页控件,自己设计,供大家参考,具体内容如下
1.主要是使用控件绑定点击事件主要是使用控件绑定点击事件
用到的控件分别为picturebox lable 上一页pbPage_Prev 下一页 pbPage_Next 首页 pbPage_Begin 尾页pbPage_End 是picturebox控件加背景图
“第 页/ 共 页” 是一个lable “labPageInfo” 在lable上面加了一个隐藏的textbox 控件 “txtPageInfo”
2.将这个翻页的功能单独写在用户控件将这个翻页的功能单独写在用户控件 ucPageTurn 里面里面 然后在每个页面直接应用就可以了然后在每个页面直接应用就可以了
下面只是把ucPageTurn写了出来
还需要在winform页面上应用上
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;
namespace Demo
{
public partial class ucPageTurn : UserControl, IMessageFilter
{
private const int SIZE_HEIGHT = 40;
private const int SIZE_MINWIDTH = 84;
private const int SIZE_INFO_MINWIDTH = 188;
public ucPageTurn()
{
Application.AddMessageFilter(this);
InitializeComponent();
this.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.MinimumSize = new Size(SIZE_MINWIDTH, 0);
this.Disposed += new EventHandler(ucPages_Disposed);
//this.MouseClick += new MouseEventHandler(ucKeyboard_Close);
PageChanged += new PageChangedHandle(new PageChangedHandle((oldPage, newPage, e) => { }));
InputGotFocus += new InputFocusHandle(new InputFocusHandle((sender, e) => { }));
//InputLostFocus += new InputFocusHandle(new InputFocusHandle((sender, e) => { }));
InputGotFocus += new InputFocusHandle(new InputFocusHandle((sender, e) => { }));
InputLostFocus += new InputFocusHandle(new InputFocusHandle((sender, e) => { }));
InputMouseDown += new InputMouseHandle(new InputMouseHandle((sender, e) => { }));
InputMouseUp += new InputMouseHandle(new InputMouseHandle((sender, e) => { }));
InputTextClick += new EventHandler(new EventHandler((sender, e) => { }));
InputKeyDown += new InputKeyHandle(new InputKeyHandle((sender, e) => { }));
InputKeyUp += new InputKeyHandle(new InputKeyHandle((sender, e) => { }));
InputKeyPress += new InputKeyPressHandle(new InputKeyPressHandle((sender, e) => { }));
InputTextChanged += new EventHandler(new EventHandler((sender, e) => { }));
this.BackColor = Color.White;
labPageInfo.BackColor = this.BackColor;
this.Resize += new EventHandler(ucPages_Resize);
//labPageInfo.MouseDoubleClick += new MouseEventHandler(labPageInfo_MouseDoubleClick);
pbPage_Prev.MouseDown += new MouseEventHandler(pbPage_Prev_MouseDown);
pbPage_Prev.MouseUp += new MouseEventHandler(pbPage_Prev_MouseUp);
pbPage_Next.MouseDown += new MouseEventHandler(pbPage_Next_MouseDown);
pbPage_Next.MouseUp += new MouseEventHandler(pbPage_Next_MouseUp);
pbPage_Begin.MouseDown += new MouseEventHandler(pbPage_Begin_MouseDown);
pbPage_Begin.MouseUp += new MouseEventHandler(pbPage_Begin_MouseUp);
pbPage_End.MouseDown += new MouseEventHandler(pbPage_End_MouseDown);
pbPage_End.MouseUp += new MouseEventHandler(pbPage_End_MouseUp);
txtPageInfo.TextChanged += new EventHandler(txtPageInfo_TextChanged);
txtPageInfo.GotFocus += new EventHandler(txtPageInfo_GotFocus);
txtPageInfo.Click += new EventHandler(txtPageInfo_Click);
txtPageInfo.Text = m_strText;
txtPageInfo.Visible = m_blnShowTxtPageInfo;
m_blnIsAutoJump = false;
m_timerAutoPage.Enabled = false;
m_timerAutoPage.Interval = WAIT_FOR_AUTOJUMP;
m_timerAutoPage.Tick += new EventHandler(timerAutoPage_Tick);
}
private void ucPages_Load(object sender, EventArgs e)
{
setStatus();
}
private void ucPages_Disposed(object sender, EventArgs e)
{
Application.RemoveMessageFilter(this);
}
public bool PreFilterMessage(ref System.Windows.Forms.Message MyMessage)
{
if (MyMessage.Msg == 0x204 || MyMessage.Msg == 0x205)
{
return true;
}
return false;
}
//设置控件的自适应大小
private void ucPages_Resize(object sender, EventArgs e)
{
this.Height = SIZE_HEIGHT;
pbPage_Begin.Location = new Point(0, 0);
pbPage_Begin.Size = new Size(SIZE_HEIGHT, SIZE_HEIGHT);