小编Jan*_*ndy的帖子

在TabControl中增加标题的宽度和高度

我不喜欢TabControl,他们看起来很丑。所以我正在创建自己的自定义绘制TabControl。标题高度有一些问题。我的控件如下所示:

在此处输入图片说明

控件构造函数:

this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(Conbut trolStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.DrawMode = TabDrawMode.OwnerDrawFixed;
Run Code Online (Sandbox Code Playgroud)

和OnPaintBackground:

var g = pevent.Graphics;
var Count = this.TabCount - 1;
int Offset = 2;
int index = 0;
foreach (TabPage itemtab in this.TabPages)
{
  //SizeF sz = g.MeasureString(itemtab.Text, this.Font);
  var tabrect = this.GetTabRect(index);
  var headerrect = new Rectangle(tabrect.Left + Offset, tabrect.Y, tabrect.Width, tabrect.Height);
  DrawRoundedRectangle(g, Headerbrush, headerrect, 3);
  g.DrawString(itemtab.Text, this.Font, textbrush, headerrect, str);
  if (index < Count) index++;
}
Run Code Online (Sandbox Code Playgroud)

我试图添加以下行:

this.ItemSize = …
Run Code Online (Sandbox Code Playgroud)

c# tabcontrol winforms

2
推荐指数
1
解决办法
5464
查看次数

按钮的动画发光效果-C#Windows窗体

我想在按下按钮时对按钮应用动画。在WPF中,我可以Storyboard与触发器配合使用来创建动画。这是一个例子:

<Storyboard x:Key="AniOpacityDelay">
  <DoubleAnimation
    Storyboard.TargetName="background"
    Storyboard.TargetProperty="Opacity"
    AutoReverse="True"
    To="0.65"
    Duration="0:0:0.2"/>
</Storyboard>
Run Code Online (Sandbox Code Playgroud)

和:

<ColorAnimationUsingKeyFrames
  Storyboard.TargetName="Itemcont"
  Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">

  <EasingColorKeyFrame KeyTime="0" Value="#EEEEEE"/>
</ColorAnimationUsingKeyFrames>
Run Code Online (Sandbox Code Playgroud)

Windows窗体没有Storyboard和触发器。如何在Windows窗体中制作平滑的动画?

这是我的Windows窗体代码:

void DelayTime()
{
  timer = new Timer();
  timer.Interval = (int)System.TimeSpan.FromSeconds(this.DelayTime).TotalMilliseconds;
  timer.Tick += (s, es) =>
  {
    this.mouseover = false; 
    this.Cursor = Cursors.Hand;
    this.Enabled = true;
  };
  timer.Start();
}

protected override void OnMouseDown(MouseEventArgs mevent)
{
  base.OnMouseDown(mevent);
  mouseover = true;
  this.Enabled = false;
  DelayTime();
}

protected override void OnPaint(PaintEventArgs e)
{
  Color bg = this._Background;
  bg = mouseover …
Run Code Online (Sandbox Code Playgroud)

c# button custom-controls winforms

2
推荐指数
1
解决办法
2234
查看次数

标签 统计

c# ×2

winforms ×2

button ×1

custom-controls ×1

tabcontrol ×1