我想关闭按钮添加到TabPages的TabControl.我尝试这个代码,它适用于从左到右TabControl:
private Point _imageLocation = new Point(13, 5);
private Point _imgHitArea = new Point(13, 2);
this.tabControl2.DrawMode = System.Windows.Forms.TabDrawMode.OwnerDrawFixed;
tabControl2.DrawItem += TabControl2_DrawItem;
private void TabControl2_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
try
{
Image img = new Bitmap(GestionP.Properties.Resources.Close);
Rectangle r = e.Bounds;
r = this.tabControl2.GetTabRect(e.Index);
r.Offset(2, 2);
Brush TitleBrush = new SolidBrush(Color.Black);
Font f = this.Font;
string title = this.tabControl2.TabPages[e.Index].Text;
e.Graphics.DrawString(title, f, TitleBrush, new PointF(r.X, r.Y));
if (tabControl2.SelectedIndex >= 1)
{
e.Graphics.DrawImage(img, new Point(r.X + (this.tabControl2.GetTabRect(e.Index).Width - _imageLocation.X), _imageLocation.Y)); …Run Code Online (Sandbox Code Playgroud) 如何将 RightToLeft 属性设置为 DatagridviewCell?我试图设置
Alignment 属性为“MiddleRight”,但由于我的 DatagridviewCell 值为
阿拉伯语和英语从右到左没有按照我想要的方式显示。
我想在ASP.NET C#中访问CrystalReportViewer的Print事件(当我单击CrystalReportViewer的Print按钮时),怎么样?
如何将十进制数(例如2.5)转换为年和月(2年和6个月)并将其添加到给定日期?我试过了DateTime.TryParse,但没用.
我想更改TabPage标题右侧未使用空间的颜色.
我试图覆盖OnPaintBackground窗口的方法,它正在工作,这是我使用的代码:
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
Rectangle lasttabrect = tabControl1.GetTabRect(tabControl1.TabPages.Count - 1);
RectangleF emptyspacerect = new RectangleF(
lasttabrect.X + lasttabrect.Width + tabControl1.Left,
tabControl1.Top + lasttabrect.Y,
tabControl1.Width - (lasttabrect.X + lasttabrect.Width),
lasttabrect.Height);
Brush b = Brushes.BlueViolet; // the color you want
e.Graphics.FillRectangle(b, emptyspacerect);
}
Run Code Online (Sandbox Code Playgroud)
但是因为我在我的TabPages中添加了一个关闭按钮并且我使用了
`tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed`
Run Code Online (Sandbox Code Playgroud)
我改变了 tabControl1_DrawItem
上面的代码对我不起作用.
我创建了一个Windows Forms应用程序以ping ip地址列表,然后使用a Timer来每秒钟重复一次ping 30。这是我使用的代码:
private System.Timers.Timer timer;
public Form1()
{
InitializeComponent();
timer = new System.Timers.Timer();
timer.Interval = 30000;
timer.Enabled = true;
timer.Elapsed += button1_Click;
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
pingResults.Clear();
ipAddress.Add("10.100.1.1");
ipAddress.Add("10.100.1.2");
ipAddress.Add("10.100.1.3");
ipAddress.Add("10.100.1.4");
ipAddress.Add("10.100.1.5");
ipAddress.Add("10.100.1.100");
for (int i = 1; i < 7; i++)
{
pictureBoxList.Add((PictureBox)Controls.Find("pictureBox" + i, true)[0]);
}
Parallel.For(0, ipAddress.Count(), (i, loopState) =>
{
Ping ping = new Ping();
PingReply pingReply = ping.Send(ipAddress[i].ToString());
this.BeginInvoke((Action)delegate()
{
pictureBoxList[i].BackColor = (pingReply.Status == …Run Code Online (Sandbox Code Playgroud)