软件编程
位置:首页>> 软件编程>> C#编程>> C#中Winform 实现Ajax效果自定义按钮

C#中Winform 实现Ajax效果自定义按钮

作者:数据酷软件  发布时间:2022-05-14 08:22:51 

标签:Winform,Ajax

技术看点

  1.  WinForm自定义控件的使用

  2. 自定义控件gif动画的播放

需求及效果

又来一波 C# GDI自定义控件show 。这个控件已经使用几年了,最近找出来重构一下。原来是没有边框的,那么导致导航的功能不是很突出。本来想加个效果:在执行单击时显示Loading动画,在执行完单击事件后恢复原样。这就是网页里见到的局部刷新,Ajax常用的场景。需求来自几年前一个智能储物柜项目,人机界面有个美工设计好的效果图,为了省事和通用,需要一个透明的按钮来实现导航的任务。就是控件只是设计时可见,运行时不可见。

C#中Winform 实现Ajax效果自定义按钮

C#中Winform 实现Ajax效果自定义按钮

 C#中Winform 实现Ajax效果自定义按钮

关键点说明

1)、GraphicsPath实现矩形的圆角羽化处理


using (GraphicsPath path = new GraphicsPath())
  {
   #region 羽化,圆角处理
   path.StartFigure();
   path.AddArc(new Rectangle(new Point(rect.X, rect.Y), new Size(2 * Radius, 2 * Radius)), 180, 90);
   path.AddLine(new Point(rect.X + Radius, rect.Y), new Point(rect.Right - Radius, rect.Y));
   path.AddArc(new Rectangle(new Point(rect.Right - 2 * Radius, rect.Y), new Size(2 * Radius, 2 * Radius)), 270, 90);
   path.AddLine(new Point(rect.Right, rect.Y + Radius), new Point(rect.Right, rect.Bottom - Radius));
   path.AddArc(new Rectangle(new Point(rect.Right - 2 * Radius, rect.Bottom - 2 * Radius), new Size(2 * Radius, 2 * Radius)), 0, 90);
   path.AddLine(new Point(rect.Right - Radius, rect.Bottom), new Point(rect.X + Radius, rect.Bottom));
   path.AddArc(new Rectangle(new Point(rect.X, rect.Bottom - 2 * Radius), new Size(2 * Radius, 2 * Radius)), 90, 90);
   path.AddLine(new Point(rect.X, rect.Bottom - Radius), new Point(rect.X, rect.Y + Radius));
   path.CloseFigure();
   #endregion

要点就是画几段弧线和矩形连接起来。透明就是用了Color.FromArgb加上透明度,然后填充GraphicsPath形成透明区域。


g.FillPath(new SolidBrush(Color.FromArgb(153, BackColor)), path);

2)、单窗体应用如何模块化 

窗体只有一个,但操作界面好多个,由于是无人值守的应用。那么老是切换窗体操作是非常不方便的。工作区域是一个容器Panel,把每个操作界面定义成一个Panel作为只容器。


public partial class DepositBizPanel : UserControl
{
 private BackgroundStyle backgroundStyle = BackgroundStyle.Green;
 /// <summary>
 /// 主题风格
 /// </summary>
 public BackgroundStyle BackgroundStyle
 {
  get { return backgroundStyle; }
  set
  {
   backgroundStyle = value;
   switch (value)
   {
    case GreenlandExpressBox.BackgroundStyle.Blue:
     BackgroundImage = Properties.Resources.jbblue;
     break;
    case GreenlandExpressBox.BackgroundStyle.Orange:
     BackgroundImage = Properties.Resources.jborange;
     break;
    case GreenlandExpressBox.BackgroundStyle.Green:
     BackgroundImage = Properties.Resources.jbgreen;
     break;
   }
   Invalidate();
  }
 }

public Panel ParentPanel
 {
  get;
  set;
 }

public Bitmap QR_Barcode
 {
  get { return (Bitmap)pbxBarcode.Image; }
  set { pbxBarcode.Image = value; }
 }

public DialogResult PanelDiagResult
 {
  get;
  set;
 }

public DepositBizPanel(Panel parent, Bitmap barcode, BackgroundStyle style)
 {
  InitializeComponent();
  DoubleBuffered = true;
  ParentPanel = parent;
  QR_Barcode = barcode;
  BackgroundStyle = style;
 }  

private void btnback_Click(object sender, EventArgs e)
 {
  foreach (Control panel in ParentPanel.Controls)
  {
   if (panel is DepositBizPanel)
   {
    ParentPanel.Controls.Remove(panel);
    PanelDiagResult = DialogResult.Cancel;
    break;
   }
  }
 }

private void btnprocessnext_Click(object sender, EventArgs e)
 {
  foreach (Control panel in ParentPanel.Controls)
  {
   if (panel is DepositBizPanel)
   {
    ParentPanel.Controls.Remove(panel);
    PanelDiagResult = DialogResult.OK;
    break;
   }
  }
 }
}

人机操作界面例子

 3)、控件播放gif动画


private void BeginAnimate()
 {
  if (m_AnimateImage == null)
   return;
  if (ImageAnimator.CanAnimate(m_AnimateImage))
  {
   //当gif动画每隔一定时间后,都会变换一帧,那么就会触发一事件,
   //该方法就是将当前image每变换一帧时,都会调用当前这个委托所关联的方法。
   ImageAnimator.Animate(m_AnimateImage, m_evthdlAnimator);
  }
 }
 private void StopAnimate()
 {
  if (m_AnimateImage == null)
   return;
  try
  {
   if (ImageAnimator.CanAnimate(m_AnimateImage))
   {
    ImageAnimator.StopAnimate(m_AnimateImage, m_evthdlAnimator);
   }
  }
  finally
  {
   m_IsExecuted = false;
  }
 }
 private void UpdateImage()
 {
  if (m_AnimateImage == null)
   return;
  if (ImageAnimator.CanAnimate(m_AnimateImage))
  {
   //获得当前gif动画的下一步需要渲染的帧,当下一步任何对当前gif动画的操作都是对该帧进行操作)
   ImageAnimator.UpdateFrames(m_AnimateImage);
  }
 }
 private void OnImageAnimate(Object sender, EventArgs e)
 {
  Invalidate();
 }
 protected override void OnLoad(EventArgs e)
 {
  base.OnLoad(e);
  string s1 = @"R0lGODlhIAAgALMAAP///7Ozs/v7+9bW1uHh4fLy8rq6uoGBgTQ0NAEBARsbG8TExJeXl/39/VRUVAAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQFBQAAACwAAAAAIAAgAAAE5xDISSlLrOrNp0pKNRCdFhxVolJLEJQUoSgOpSYT4RowNSsvyW1icA16k8MMMRkCBjskBTFDAZyuAEkqCfxIQ2hgQRFvAQEEIjNxVDW6XNE4YagRjuBCwe60smQUDnd4Rz1ZAQZnFAGDd0hihh12CEE9kjAEVlycXIg7BAsMB6SlnJ87paqbSKiKoqusnbMdmDC2tXQlkUhziYtyWTxIfy6BE8WJt5YEvpJivxNaGmLHT0VnOgGYf0dZXS7APdpB309RnHOG5gDqXGLDaC457D1zZ/V/nmOM82XiHQjYKhKP1oZmADdEAAAh+QQFBQAAACwAAAAAGAAXAAAEchDISasKNeuJFKoHs4mUYlJIkmjIV54Soypsa0wmLSnqoTEtBw52mG0AjhYpBxioEqRNy8V0qFzNw+GGwlJki4lBqx1IBgjMkRIghwjr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10Is6mT5gdVFx1bRN8FTsVCAqDOB9+KhEAIfkEBQUAAAAsAgASAB0ADgAABHgQyEmrBePS4bQdQZBdR5IcHmWEgUFQgWKaKbWwwSIhc4LonsXhBSCsQoOSScGQDJiWwOHQnAxWBIYJNXEoFCiEWDI9jCzESey7GwMM5doEwW4jJoypQQ743u1WcTV0CgFzbhJ5XClfHYd/EwZnHoYVDgiOfHKQNREAIfkEBQUAAAAsAAAPABkAEQAABGeQqUQruDjrW3vaYCZ5X2ie6EkcKaooTAsi7ytnTq046BBsNcTvItz4AotMwKZBIC6H6CVAJaCcT0CUBTgaTg5nTCu9GKiDEMPJg5YBBOpwlnVzLwtqyKnZagZWahoMB2M3GgsHSRsRACH5BAUFAAAALAEACAARABgAAARcMKR0gL34npkUyyCAcAmyhBijkGi2UW02VHFt33iu7yiDIDaD4/erEYGDlu/nuBAOJ9Dvc2EcDgFAYIuaXS3bbOh6MIC5IAP5Eh5fk2exC4tpgwZyiyFgvhEMBBEAIfkEBQUAAAAsAAACAA4AHQAABHMQyAnYoViSlFDGXBJ808Ep5KRwV8qEg+pRCOeoioKMwJK0Ekcu54h9AoghKgXIMZgAApQZcCCu2Ax2O6NUud2pmJcyHA4L0uDM/ljYDCnGfGakJQE5YH0wUBYBAUYfBIFkHwaBgxkDgX5lgXpHAXcpBIsRADs=";
  byte[] buffer = Convert.FromBase64String(s1);
  MemoryStream ms = new MemoryStream(buffer);
  var srcImg = Image.FromStream(ms);
  m_AnimateImage = srcImg;
 }

OnLoad执行的操作是从base64字符串里反序列化图片,就是效果图中的Loading的gif图片。这里遇到一个问题:在关闭了MemoryStream之后,会出现“gdi+ 中发生一般性错误”,于是改为不关闭了,控件销毁之后占用的内存就会释放吧。这是一点隐忧,如果有好的办法,希望留言告知。

透明按钮自定义控件全部代码

第一版自定义按钮:


/// <summary>
/// Cool透明自定义按钮
/// </summary>
public partial class CoolTransparentButton : UserControl
{
 private Size iconSize = new Size(32, 32);
 public Size IconSize
 {
  get
  {
   return iconSize;
  }
  set
  {
   iconSize = value;
   Invalidate();
  }
 }
 private string _ButtonText;
 public string ButtonText
 {
  get { return _ButtonText; }
  set
  {
   _ButtonText = value;
   Invalidate();
  }
 }
 protected Image _IconImage;
 public Image IconImage
 {
  get
  {
   return _IconImage;
  }
  set
  {
   _IconImage = value;
   Invalidate();
  }
 }
 private bool _FocseActived = false;
 private Color _BorderColor = Color.White;
 public Color BorderColor
 {
  get
  {
   return _BorderColor;
  }
  set
  {
   _BorderColor = value;
   Invalidate();
  }
 }
 private int _Radius = 12;
 public int Radius
 {
  get
  {
   return _Radius;
  }
  set
  {
   _Radius = value;
   Invalidate();
  }
 }
 private bool ifDrawBorderWhenLostFocse = true;
 /// <summary>
 /// 失去焦点是否画边框
 /// </summary>
 public bool IfDrawBorderWhenLostFocse
 {
  get
  {
   return ifDrawBorderWhenLostFocse;
  }
  set
  {
   ifDrawBorderWhenLostFocse = value;
   Invalidate();
  }
 }
 /// <summary>
 /// 是否处于激活状态(焦点)
 /// </summary>
 public bool FocseActived
 {
  get { return _FocseActived; }
  set
  {
   _FocseActived = value;
   Invalidate();
  }
 }  
 public CoolTransparentButton()
 {
  DoubleBuffered = true;
  BackColor = Color.Transparent;
  SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
  SetStyle(ControlStyles.Opaque, false);
  UpdateStyles();
 }
 protected override void OnPaint(PaintEventArgs e)
 {
  var rect = ClientRectangle;
  rect.Inflate(-1, -1);
  Graphics g = e.Graphics;
  g.SmoothingMode = SmoothingMode.HighQuality;
  using (GraphicsPath path = new GraphicsPath())
  {
   #region 羽化,圆角处理
   path.StartFigure();
   path.AddArc(new Rectangle(new Point(rect.X, rect.Y), new Size(2 * Radius, 2 * Radius)), 180, 90);
   path.AddLine(new Point(rect.X + Radius, rect.Y), new Point(rect.Right - Radius, rect.Y));
   path.AddArc(new Rectangle(new Point(rect.Right - 2 * Radius, rect.Y), new Size(2 * Radius, 2 * Radius)), 270, 90);
   path.AddLine(new Point(rect.Right, rect.Y + Radius), new Point(rect.Right, rect.Bottom - Radius));
   path.AddArc(new Rectangle(new Point(rect.Right - 2 * Radius, rect.Bottom - 2 * Radius), new Size(2 * Radius, 2 * Radius)), 0, 90);
   path.AddLine(new Point(rect.Right - Radius, rect.Bottom), new Point(rect.X + Radius, rect.Bottom));
   path.AddArc(new Rectangle(new Point(rect.X, rect.Bottom - 2 * Radius), new Size(2 * Radius, 2 * Radius)), 90, 90);
   path.AddLine(new Point(rect.X, rect.Bottom - Radius), new Point(rect.X, rect.Y + Radius));
   path.CloseFigure();
   #endregion
   if (!FocseActived)
   {
    if (ifDrawBorderWhenLostFocse)
     g.DrawPath(new Pen(Color.Gray, 1), path);
    g.FillPath(new SolidBrush(Color.FromArgb(66, BackColor)), path);
   }
   else
   {
    g.DrawPath(new Pen(BorderColor, 1), path);
    rect.Inflate(-1, -1);
    g.FillPath(new SolidBrush(Color.FromArgb(153, BackColor)), path);
   }
   #region 画文本
   g.SmoothingMode = SmoothingMode.AntiAlias;
   if (IconImage != null)
   {
    Rectangle rc = new Rectangle((Width - 32) / 2, 16, IconSize.Width, IconSize.Height);
    g.DrawImage(IconImage, rc);
   }
   if (!string.IsNullOrEmpty(ButtonText))
   {
    using (StringFormat f = new StringFormat())
    {
     Rectangle rectTxt = new Rectangle(0, (Height - 18) / 2, Width, 36);
     f.Alignment = StringAlignment.Center;// 水平居中对齐
     f.LineAlignment = StringAlignment.Center; // 垂直居中对齐
     f.FormatFlags = StringFormatFlags.NoWrap;// 设置为单行文本
     SolidBrush fb = new SolidBrush(this.ForeColor); // 绘制文本
     e.Graphics.DrawString(ButtonText, new Font("微软雅黑", 16F, FontStyle.Bold), fb, rectTxt, f);
    }
   }
   #endregion
  }
 }
 protected override void OnMouseHover(EventArgs e)
 {
  FocseActived = true;
 }
 protected override void OnMouseLeave(EventArgs e)
 {
  FocseActived = false;
 }
 protected override void OnEnter(EventArgs e)
 {
  FocseActived = true;
 }
 protected override void OnLeave(EventArgs e)
 {
  FocseActived = false;
 }
}

第二版自定义按钮:


/// <summary>
/// 自定义透明自定义按钮,模仿实现了网页元素的Ajax效果
/// </summary>
public partial class AjaxTransparentButton : UserControl
{
 private Size iconSize = new Size(32, 32);
 public Size IconSize
 {
  get
  {
   return iconSize;
  }
  set
  {
   iconSize = value;
   Invalidate();
  }
 }
 private string _ButtonText;
 public string ButtonText
 {
  get { return _ButtonText; }
  set
  {
   _ButtonText = value;
   Invalidate();
  }
 }
 protected Image _IconImage;
 public Image IconImage
 {
  get
  {
   return _IconImage;
  }
  set
  {
   _IconImage = value;
   Invalidate();
  }
 }
 private bool _FocseActived = false;
 private Color _BorderColor = Color.White;
 public Color BorderColor
 {
  get
  {
   return _BorderColor;
  }
  set
  {
   _BorderColor = value;
   Invalidate();
  }
 }
 private int _Radius = 12;
 public int Radius
 {
  get
  {
   return _Radius;
  }
  set
  {
   _Radius = value;
   Invalidate();
  }
 }
 private bool ifDrawBorderWhenLostFocse = true;
 /// <summary>
 /// 失去焦点是否画边框
 /// </summary>
 public bool IfDrawBorderWhenLostFocse
 {
  get
  {
   return ifDrawBorderWhenLostFocse;
  }
  set
  {
   ifDrawBorderWhenLostFocse = value;
   Invalidate();
  }
 }
 /// <summary>
 /// 是否处于激活状态(焦点)
 /// </summary>
 public bool FocseActived
 {
  get { return _FocseActived; }
  set
  {
   _FocseActived = value;
   Invalidate();
  }
 }
 private Image m_AnimateImage = null;
 private EventHandler m_evthdlAnimator = null;
 private bool m_IsExecuted = false;
 public AjaxTransparentButton()
 {
  BackColor = Color.Transparent;
  SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
  SetStyle(ControlStyles.Opaque, false);
  UpdateStyles();
  m_evthdlAnimator = new EventHandler(OnImageAnimate);
 }
 protected override void OnPaint(PaintEventArgs e)
 {
  var rect = ClientRectangle;
  rect.Inflate(-1, -1);
  Graphics g = e.Graphics;
  g.SmoothingMode = SmoothingMode.HighQuality;
  using (GraphicsPath path = new GraphicsPath())
  {
   #region 羽化,圆角处理
   path.StartFigure();
   path.AddArc(new Rectangle(new Point(rect.X, rect.Y), new Size(2 * Radius, 2 * Radius)), 180, 90);
   path.AddLine(new Point(rect.X + Radius, rect.Y), new Point(rect.Right - Radius, rect.Y));
   path.AddArc(new Rectangle(new Point(rect.Right - 2 * Radius, rect.Y), new Size(2 * Radius, 2 * Radius)), 270, 90);
   path.AddLine(new Point(rect.Right, rect.Y + Radius), new Point(rect.Right, rect.Bottom - Radius));
   path.AddArc(new Rectangle(new Point(rect.Right - 2 * Radius, rect.Bottom - 2 * Radius), new Size(2 * Radius, 2 * Radius)), 0, 90);
   path.AddLine(new Point(rect.Right - Radius, rect.Bottom), new Point(rect.X + Radius, rect.Bottom));
   path.AddArc(new Rectangle(new Point(rect.X, rect.Bottom - 2 * Radius), new Size(2 * Radius, 2 * Radius)), 90, 90);
   path.AddLine(new Point(rect.X, rect.Bottom - Radius), new Point(rect.X, rect.Y + Radius));
   path.CloseFigure();
   #endregion
   if (!FocseActived)
   {
    if (ifDrawBorderWhenLostFocse)
     g.DrawPath(new Pen(Color.Gray, 1), path);
    g.FillPath(new SolidBrush(Color.FromArgb(66, BackColor)), path);
   }
   else
   {
    g.DrawPath(new Pen(BorderColor, 1), path);
    rect.Inflate(-1, -1);
    g.FillPath(new SolidBrush(Color.FromArgb(153, BackColor)), path);
   }
   #region 画文本
   g.SmoothingMode = SmoothingMode.AntiAlias;
   if (IconImage != null)
   {
    Rectangle rc = new Rectangle((Width - 32) / 2, 16, IconSize.Width, IconSize.Height);
    g.DrawImage(IconImage, rc);
   }
   if (!string.IsNullOrEmpty(ButtonText))
   {
    using (StringFormat f = new StringFormat())
    {
     Rectangle rectTxt = new Rectangle(0, (Height - 18) / 2, Width, 36);
     f.Alignment = StringAlignment.Center;// 水平居中对齐
     f.LineAlignment = StringAlignment.Center; // 垂直居中对齐
     f.FormatFlags = StringFormatFlags.NoWrap;// 设置为单行文本
     SolidBrush fb = new SolidBrush(this.ForeColor); // 绘制文本
     e.Graphics.DrawString(ButtonText, new Font("微软雅黑", 16F, FontStyle.Bold), fb, rectTxt, f);
    }
   }
   if (m_AnimateImage != null)
   {
    Rectangle rectGif = new Rectangle((Width - 24) / 2, (Height - 16) / 2 - 8, 32, 32);
    if (m_IsExecuted)
    {
     UpdateImage();
     e.Graphics.DrawImage(m_AnimateImage, rectGif);
    }
    else
    {
     e.Graphics.FillRectangle(new SolidBrush(Color.Transparent), rectGif);
    }
   }
   #endregion
  }
 }
 protected override void OnMouseHover(EventArgs e)
 {
  FocseActived = true;
 }
 protected override void OnMouseLeave(EventArgs e)
 {
  FocseActived = false;
 }
 protected override void OnEnter(EventArgs e)
 {
  FocseActived = true;
 }
 protected override void OnLeave(EventArgs e)
 {
  FocseActived = false;
 }
 private void BeginAnimate()
 {
  if (m_AnimateImage == null)
   return;
  if (ImageAnimator.CanAnimate(m_AnimateImage))
  {
   //当gif动画每隔一定时间后,都会变换一帧,那么就会触发一事件,
   //该方法就是将当前image每变换一帧时,都会调用当前这个委托所关联的方法。
   ImageAnimator.Animate(m_AnimateImage, m_evthdlAnimator);
  }
 }
 private void StopAnimate()
 {
  if (m_AnimateImage == null)
   return;
  try
  {
   if (ImageAnimator.CanAnimate(m_AnimateImage))
   {
    ImageAnimator.StopAnimate(m_AnimateImage, m_evthdlAnimator);
   }
  }
  finally
  {
   m_IsExecuted = false;
  }
 }
 private void UpdateImage()
 {
  if (m_AnimateImage == null)
   return;
  if (ImageAnimator.CanAnimate(m_AnimateImage))
  {
   //获得当前gif动画的下一步需要渲染的帧,当下一步任何对当前gif动画的操作都是对该帧进行操作)
   ImageAnimator.UpdateFrames(m_AnimateImage);
  }
 }
 private void OnImageAnimate(Object sender, EventArgs e)
 {
  Invalidate();
 }
 protected override void OnLoad(EventArgs e)
 {
  base.OnLoad(e);
  string s1 = @"R0lGODlhIAAgALMAA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BEAIfkEBQUAAAAsAAACAA4AHQAABHMQyAnYoViSlFDGXBJ808Ep5KRwV8qEg+pRCOeoioKMwJK0Ekcu54h9AoghKgXIMZgAApQZcCCu2Ax2O6NUud2pmJcyHA4L0uDM/ljYDCnGfGakJQE5YH0wUBYBAUYfBIFkHwaBgxkDgX5lgXpHAXcpBIsRADs=";
  byte[] buffer = Convert.FromBase64String(s1);
  MemoryStream ms = new MemoryStream(buffer);
  var srcImg = Image.FromStream(ms);
  m_AnimateImage = srcImg;
 }
 protected override void OnClick(EventArgs e)
 {
  if (m_IsExecuted)
   return;
  Action clickTask = () =>
  {
   m_IsExecuted = true;
   BeginAnimate();
   base.OnClick(e);
   Invalidate();
  };
  //异步执行单击事件
  clickTask.BeginInvoke((result) =>
  {
   clickTask.EndInvoke(result);
   m_IsExecuted = false;
   StopAnimate();
  }, null);
 }
 protected override void Dispose(bool disposing)
 {
  base.Dispose(disposing);
  if (m_AnimateImage != null)
  {
   try
   {
    StopAnimate();
   }
   finally
   {
    m_AnimateImage.Dispose();
    m_evthdlAnimator = null;
   }
  }
 }
 protected override void OnKeyDown(KeyEventArgs e)
 {
  base.OnKeyDown(e);
  if (e.KeyCode == Keys.Enter)
  {
   OnClick(e);
  }
 }
}

注释不是很多,源码如有需要拿走不谢

来源:http://www.cnblogs.com/datacool/p/datacool_2017_ajax_button.html

0
投稿

猜你喜欢

  • Stream.Read 方法当在派生类中重写时,从当前流读取字节序列,并将此流中的位置提升读取的字节数。语法:public abstract
  • 研发背景公司安全部目前针对内部系统的网络访问日志的安全审计,大部分都是T+1时效,每日当天,启动Python编写的定时任务,完成昨日的日志审
  • 1 使用阿里的FastJson1.1 项目的pom.xml依赖<dependency> <groupId>com.a
  • 1 仿射变换仿射变换:一种二维坐标到二维坐标的线性变换,它保持二维图像的平直性与平行性,即变换后直线依然是直线,平行的线依然平行。packa
  • 本文实例为大家分享了C#实现飞行棋的具体代码,供大家参考,具体内容如下基于Winform框架写的不足之处请大佬指教using System;
  • 本文实例讲述了Java操作redis实现增删查改功能的方法。分享给大家供大家参考,具体如下:首先,我们需要在windows下配置一个redi
  • 本文实例为大家分享了java实现滑动验证解锁的具体代码,供大家参考,具体内容如下1.html:<div class="dra
  • 背景年初开始我们就开始了关于Gradle Sync阶段的优化。之前和大家都简单的介绍过工程相关的背景情况了,我们大概有400+的Module
  • Java发红包案例,供大家参考,具体内容如下首先我们需要分析这个代码的架构是什么,需要什么类组成等。我们需要建立4个类,这4个类分别是用户类
  • 本文实现了一个有趣的小东西:使用自定义View绘图,一边画线,画出的线条渐渐变淡,直到消失。效果如下图所示:用属性动画或者渐变填充(Shad
  • 开发中,对于不经常使用英语的同学来说,对类,变量,方法想取一个合适的名字,此时发现自己的词汇早已还给老师 ,怎么办,这个插件能帮到你~一、安
  • 本文实例讲述了C#实现带阴历显示的日期代码,分享给大家供大家参考。具体方法如下:这是一个用于酒店预定功能的带日期控件,类似去哪网酒店预定,由
  • 第1部分 TreeSet介绍TreeSet简介TreeSet 是一个有序的集合,它的作用是提供有序的Set集合。它继承于AbstractSe
  • 要点有另一种方法来完成语句映射。 它们映射的语句可以不用 XML 来配置,而可以使用 Java 注解来配置。使用注解来映射简单语句会使代码显
  • 账户类Account:Id:账户号码PassWord:账户密码Name:真实姓名PersonId:身份证号码Email:客户的电子邮箱Bal
  • 大致思路:注解实现方式:就是用 反射机制. 获取指定的包下使用了注解的类,存储在一个map容器, 然后获取map容器下类的属性, 利用反射给
  • 本文实例为大家分享了OpenGL绘制Bezier曲线的具体代码,供大家参考,具体内容如下最近在看Francis S Hill ,Jr 和 S
  • 我们从jdk8说起。主要是四个随机数生成器。神马?有四个?接下来我们简单说下这几个类的使用场景,来了解其中的细微差别,和api设计者的良苦用
  • 前言最近业务开发部门因为开发环境和测试环境共用一个maven私仓,导致他们开发环境的API包和测试环境的API包发生了覆盖现象。于是他们向我
  • 前言OpenTelemetry作为一个分布式追踪的项目,他支持非常多的语言,如Java,Golang,Python等,鉴于笔者的主力语言为J
手机版 软件编程 asp之家 www.aspxhome.com