TableLayoutPanelTab控件的使用
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
代码片段:
这段代码描述了TableLayoutPanelTab控件的使用,在tableLayoutPanelTab中添加RadioButton控件,及其动态设置其属性的方法
public partial class FormFXFD : Form
{
FXFD Resource;
public FormFXFD(string PTtype, string FirstResID) { InitializeComponent(); if (PTtype == "PTFXFD") Resource = new FXFD(PTtype, FirstResID); else Resource = new FXFD(FirstResID); }
private void FormFXFD_FormClosing(object sender, FormClosingEventArgs e) { Resource.Close(); }
private void FormFXFD_Load(object sender, EventArgs e)
{
Text = " " + Resource.Title;
webBrowserContent.ScriptErrorsSuppressed = false;
tableLayoutPanelTab.Controls.Clear();
tableLayoutPanelTab.RowStyles.Clear();
tableLayoutPanelTab.ColumnCount = Resource.Count;
for (int i = 0; i < tableLayoutPanelTab.ColumnCount; i++)
{
RadioButton rb = new RadioButton();
rb.Text = Resource[i].Title;
rb.Tag = Resource[i];
rb.Font = new Font("宋体", 12);
rb.TextAlign = ContentAlignment.MiddleCenter;
rb.Dock = DockStyle.Fill;
rb.Size = new Size(111, 38);
rb.AutoEllipsis = false;
rb.BackColor = Color.Transparent;
rb.FlatAppearance.BorderSize = 0;
rb.Appearance = Appearance.Button;
rb.FlatStyle = FlatStyle.Flat;
rb.ImageList = imageListTab;
rb.ImageIndex = 0;
rb.BackgroundImageLayout = ImageLayout.Stretch;
tableLayoutPanelTab.Controls.Add(rb);
tableLayoutPanelTab.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 111));
rb.MouseMove += new System.Windows.Forms.MouseEventHandler(this.radioButton_MouseMove);
rb.MouseLeave += new System.EventHandler(this.radioButton_MouseLeave);
rb.CheckedChanged += new System.EventHandler(this.radioButtonTab_CheckedChanged);
}
if (tableLayoutPanelTab.ColumnCount > 0) ((RadioButton)tableLayoutPanelTab.Controls[0]).Checked = true;
if (Resource.bContent)
{
panelLeft.Visible = false;
panelPage.Visible = false;
webBrowserContent.Width = panelContent.Width - 40;
ShowHtm(Resource.Addr);
}
}
private void radioButton_MouseMove(object sender, MouseEventArgs e) { RadioButton rb = (RadioButton)sender; if (!rb.Checked) rb.ImageIndex = 0; }
private void radioButton_MouseLeave(object sender, EventArgs e) { RadioButton rb = (RadioButton)sender; if (!rb.Checked) rb.ImageIndex = 0; }
RadioButton CurrTab;
private void radioButtonTab_CheckedChanged(object sender, EventArgs e)
{
CurrTab = (Radi
oButton)sender; CurrTab.ImageIndex = CurrTab.Checked ? 2 : 0;
panelRight.Visible = CurrTab.Text == "基础过关";
if (CurrTab.Checked)
{
FXFD.Module Module = (FXFD.Module)CurrTab.Tag;
tableLayoutPanelItem.Controls.Clear();
tableLayoutPanelItem.RowStyles.Clear();
tableLayoutPanelItem.RowCount = Module.Count;
panelLeft.Visible = tableLayoutPanelItem.RowCount != 0;
webBrowserContent.Width = panelContent.Width - 40;
if (tableLayoutPanelItem.RowCount == 0) ShowHtm(Module.Addr);
tableLayoutPanelItem.AutoScroll= true;
for (int i = 0; i < tableLayoutPanelItem.RowCount; i++)
{
RadioButton rb = new RadioButton();
rb.Text = Module[i].Title+" "+Module[i].ID;
rb.Tag = Module[i];
rb.Font = new Font("宋体", 12);
rb.Dock = DockStyle.Top;//.Fill;
rb.Size = new Size(211, 62);
rb.AutoEllipsis = false;
rb.BackColor = Color.Transparent;
rb.BackgroundImage = panelTop.BackgroundImage;
rb.FlatAppearance.BorderSize = 0;
rb.Appearance = Appearance.Button;
rb.FlatStyle = FlatStyle.Flat;
rb.ImageList = imageListItem;
rb.ImageIndex = 0;
rb.BackgroundImageLayout = ImageLayout.Stretch;
tableLayoutPanelItem.Controls.Add(rb);
tableLayoutPanelItem.RowStyles.Add(new RowStyle(SizeType.Absolute, 62));
rb.MouseMove += new System.Windows.Forms.MouseEventHandler(this.radioButton_MouseMove);
rb.MouseLeave += new System.EventHandler(this.radioButton_MouseLeave);
rb.CheckedChanged += new System.EventHandler(this.radioButtonItem_CheckedChanged);
}
if(tableLayoutPanelItem.RowCount>0)radioButtonItem_CheckedChanged(tableLayoutPanelItem.Controls[0], null);
}
}
FXFD.Module.Item CurrItem = null; int CurrPageNo = 0;
private void radioButtonItem_CheckedChanged(object sender, EventArgs e)
{
//MessageBox.Show(((RadioButton)sender).Text);
if (((RadioButton)sender).Checked) ((RadioButton)sender).ImageIndex = 2; else ((RadioButton)sender).ImageIndex = 0;
FXFD.Module.Item item = (FXFD.Module.Item)((RadioButton)sender).Tag; CurrItem = item;
labelID.Text = item.ID+" "+item.Addr;
if (item.Addr != "") { panelPage.Visible = false; ShowHtm(item.Addr); }
else if (item.Count > 0) { CurrPageNo = 0; ShowHtm(item[CurrPageNo].Addr); ShowpanelPage(item.Count); }
}
private bool SetRadioButtonTag(RadioButton rb
)
{ foreach (FXFD.Module Module in Resource) if (Module.Title == .Substring(11, 4)) { rb.Tag = Module; return true; } return false; }
private void buttonNext_Click(object sender, EventArgs e) { if (CurrPageNo < CurrItem.Count - 1) { CurrPageNo++; ShowHtm(CurrItem[CurrPageNo].Addr); ShowpanelPage(CurrItem.Count); } }
private void buttonPrev_Click(object sender, EventArgs e) { if (CurrPageNo > 0) { CurrPageNo--; ShowHtm(CurrItem[CurrPageNo].Addr); ShowpanelPage(CurrItem.Count); } }
private void ShowHtm(string fn) { if (File.Exists(fn)) webBrowserContent.Navigate(fn); else webBrowserContent.DocumentText = fn; }
private void ShowpanelPage(int PageCount)
{
labelPageNo.Text = (CurrPageNo + 1).ToString() + "/" + PageCount.ToString();
buttonNext.Enabled = CurrPageNo < PageCount - 1;
buttonPrev.Enabled = CurrPageNo > 0;
panelPage.Visible = true;
}
private void webBrowserContent_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{ /*if (CurrTab.Text == "基础过关") webBrowserContent.Document.All["import"].Click += new HtmlElementEventHandler(标记重点_Click); */}
private void 标记重点_Click(object sender, HtmlElementEventArgs e)
{
string v = ((HtmlElement)sender).GetAttribute("value");
if(v=="取消重点") MessageBox.Show("标记为重点");
if (v == "标记为重点") MessageBox.Show("取消重点");
}
private void button1_Click(object sender, EventArgs e)
{
//string s = webBrowserContent.doc.Document.co
//for (int i = 0; i < webBrowserContent.Document.Forms.Count; i++)
//s+=webBrowserContent.Document.Forms[i].Id+"\n";
//this.webBrowser1.Document.Forms["FORM1"].InvokeMember("submit");
//string s = webBrowserContent.Document.Body.Document.All[0].OuterText;
//for (int i = 0; i < webBrowserContent.Document.Body..All.Count; i++) s += webBrowserContent.Document.Body.All[i].OuterHtml +" ====== "+ webBrowserContent.Document.Body.All[i].OuterText + "\r\n";
//MessageBox.Show(s);
}
}