本文介绍了如果在C#win表单中选中单选按钮,如何更改tabcontro的l背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
美好的一天,我正在构建一个cbt应用程序,我从头开始构建一个tabcontrol,tabpage,标签和单选按钮,但我希望tabcontrol为红色,但每当我点击单选按钮时tabcontrol应该是绿色但我很困惑因为如果我使用拖放tabcontrol,选项卡控件才会变色
我尝试过:
Good day please i am building a cbt app, i built a tabcontrol,tabpage,label and radio button from scratch but i want the tabcontrol to be red but whenever i click the radio button the tabcontrol should be green but i am confused because the tab control only get colored if i use the drag and drop tabcontrol
What I have tried:
TabControl tabControl = new TabControl();
//i have made the tabcontrol draw mode to be ownerdrawfixed
private void tabControl_DrawItem(object sender, DrawItemEventArgs e)
{//this is to color my tabcontrol but nothing happens,it only works if i use drag and drop tabcontrol
Brush txt, box_brush;
Pen bp;
Rectangle tab_rect = tabControl.GetTabRect(e.Index);
if (e.State == DrawItemState.Selected)
{
e.Graphics.FillRectangle(Brushes.Red, tab_rect);
e.DrawFocusRectangle();
txt = Brushes.Black;
box_brush = Brushes.Silver;
bp = Pens.DarkBlue;
}
else
{
e.Graphics.FillRectangle(Brushes.Red, tab_rect);
txt = Brushes.Blue;
box_brush = Brushes.Silver;
bp = Pens.DarkBlue;
}
//BUT I CREATED THE BUTTON UNDER BTNQUESTION
public void btnquestion_Click(object sender, EventArgs e)
{
this.Controls.Add(tabControl);
int page;
//am= amount of the questions
int am=20;
for (int i = 0; i < am; i++)
{
TabPage tp = new TabPage();
page = i + 1;
tp.Text = page.ToString();
tabControl.Controls.Add(tp);
Label lb1 = new Label();
RadioButton r1 = new RadioButton();
RadioButton r2 = new RadioButton();
RadioButton r3 = new RadioButton();
RadioButton r4 = new RadioButton();
//i have done the locations and the font
tp.Controls.Add(lb1);
tp.Controls.Add(r1);
tp.Controls.Add(r2);
tp.Controls.Add(r3);
tp.Controls.Add(r4);
}
推荐答案
这篇关于如果在C#win表单中选中单选按钮,如何更改tabcontro的l背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!