欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實現(xiàn)簡單的loading提示控件實例代碼

 更新時間:2017年09月03日 11:50:39   作者:季末的寂寞  
本文通過實例代碼給大家介紹了C#實現(xiàn)簡單的loading提示控件功能,代碼非常簡單,具有參考借鑒價值,需要的朋友參考下吧

自己畫一個轉(zhuǎn)圈圈的控件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ExerciseUIPrj.controls
{
  public partial class LoadControl : Control
  {
    Color beginColor = Color.Blue;
    Color endColor = Color.Red;
    int wid = 10;
    int curindex = 0;
    Timer timer;
    int instervel = 200;
    string loadStr = "loading....";
    public LoadControl()
    {
      InitializeComponent();
      SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint|ControlStyles.OptimizedDoubleBuffer, true);
      this.MinimumSize = new Size(40, 80);
      if (!DesignMode)
      {
        Start();
      }
    }
    public void Start()
    {
      if (timer == null)
      {
        timer = new Timer();
        timer.Interval = instervel;
        timer.Tick += Timer_Tick;
      }
      timer.Enabled = true;
    }
    public void Stop()
    {
      if (timer != null)
      {
        timer.Enabled = false;
      }
    }
    void Timer_Tick(object sender, EventArgs e)
    {
      curindex++;
      curindex = curindex >= wid ? 0 : curindex;
      Refresh();
    }
    //計算各種圈圈相關(guān)
    Point getPoint(double d, double r, Point center)
    {
      int x = (int)(r * Math.Cos(d * Math.PI / 180.0));
      int y = (int)(r * Math.Sin(d * Math.PI / 180.0));
      return new Point(center.X + x, center.Y - y);
    }
    GraphicsPath getPath(Point a, Point b)
    {
      Point c, d, e, f;
      int h = 2;
      Vertical(a, b, h, out c, out d);
      Vertical(b, a, h, out e, out f);
      GraphicsPath path = new GraphicsPath();
      path.AddPolygon(new Point[] { c, d, e, f });
      path.CloseAllFigures();
      return path;
    }
    bool Vertical(Point pointa, Point pointb, double R, out Point pointc, out Point pointd)
    {
      pointc = new Point();
      pointd = new Point();
      try
      {
        //(X-xa)^2+(Y-ya)^2=R*R  距離公式
        //(X-xa)*(xb-xa)+(Y-ya)*(yb-ya)=0  垂直
        //解方程得兩點即為所求點
        var cx = pointa.X - (pointb.Y - pointa.Y) * R / Distance(pointa, pointb);
        var cy = pointa.Y + (pointb.X - pointa.X) * R / Distance(pointa, pointb);
        var dx = pointa.X + (pointb.Y - pointa.Y) * R / Distance(pointa, pointb);
        var dy = pointa.Y - (pointb.X - pointa.X) * R / Distance(pointa, pointb);
        pointc = new Point((int)cx, (int)cy);
        pointd = new Point((int)dx, (int)dy);
        return true;
      }
      catch
      {
        //如果A,B兩點重合會報錯,那樣就返回false
        return false;
      }
    }
    double Distance(double xa, double ya, double xb, double yb)
    {
      double L;
      L = Math.Sqrt(Math.Pow(xa - xb, 2) + Math.Pow(ya - yb, 2));
      return L;
    }
    double Distance(Point pa, Point pb)
    {
      return Distance(pa.X, pa.Y, pb.X, pb.Y);
    }
    GraphicsPath getPath(double d, double r, Point c)
    {
      var p1 = getPoint(d, r / 2.0, c);
      var p2 = getPoint(d, r, c);
      return getPath(p1, p2);
    }
    //算漸變色
    Color[] getColors()
    {
      int dr = (int)((endColor.R - beginColor.R) / (double)wid);
      int dg = (int)((endColor.G - beginColor.G) / (double)wid);
      int db = (int)((endColor.B - beginColor.B) / (double)wid);
      List<Color> colors = new List<Color>();
      for (int i = 0; i < wid; i++)
      {
        colors.Add(Color.FromArgb(beginColor.R + dr * i, beginColor.G + dg * i, beginColor.B + db * i));
      }
      return colors.ToArray();
    }
    //畫圈圈
    void drawRect(Graphics g)
    {
      int r = (int)(Size.Height / 2.0);
      Point center = new Point(r, r);
      var colors = getColors();
      int findex = curindex;
      for (int i = 0; i < wid; i++)
      {
        double d = (360.0 / wid) * i;
        var p = getPath(d, r, center);
        int cindex = findex + i;
        cindex = cindex >= wid ? cindex - wid : cindex;
        g.FillPath(new SolidBrush(colors[cindex]), p);
      }
    }
    //畫字符串
    void drawString(Graphics g)
    {
      if (Size.Height >= Size.Width) return;
      Rectangle rect = new Rectangle(new Point(Size.Height, 0), new Size(Size.Width - Size.Height, Size.Height));
      StringFormat sf = new StringFormat();
      sf.Alignment = StringAlignment.Center;
      sf.LineAlignment = StringAlignment.Center;
      g.DrawString(loadStr, Font, Brushes.Black, rect,sf);
    }
    protected override void OnPaint(PaintEventArgs pe)
    {
      base.OnPaint(pe);
      Graphics g = pe.Graphics;
      g.SmoothingMode = SmoothingMode.HighQuality;
      g.PixelOffsetMode = PixelOffsetMode.HighQuality;
      drawRect(g);
      drawString(g);
    }
    protected override void OnSizeChanged(EventArgs e)
    {
      base.OnSizeChanged(e);
      if (Size.Height > Size.Width)
      {
        Size = new Size(Size.Height, Size.Height);
      }
    }
  }
}

總結(jié)

以上所述是小編給大家介紹的C#實現(xiàn)簡單的loading提示控件實例代碼,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!

相關(guān)文章

  • C#使用Twain協(xié)議實現(xiàn)掃描儀連續(xù)掃描功能

    C#使用Twain協(xié)議實現(xiàn)掃描儀連續(xù)掃描功能

    這篇文章主要介紹了C#使用Twain協(xié)議實現(xiàn)掃描儀連續(xù)掃描,只需一行代碼,就可實現(xiàn)一次掃描多張,且不需要更改掃描儀的任何設(shè)置,需要的朋友可以參考下
    2022-01-01
  • Unity貝塞爾曲線之美體驗

    Unity貝塞爾曲線之美體驗

    這篇文章主要帶大家體驗Unity貝塞爾曲線之美,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • Unity實現(xiàn)跑馬燈抽獎效果

    Unity實現(xiàn)跑馬燈抽獎效果

    這篇文章主要為大家詳細介紹了Unity實現(xiàn)跑馬燈抽獎效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • C#異步使用需要注意的幾個問題

    C#異步使用需要注意的幾個問題

    C#使用異步方法中,使用一下關(guān)鍵詞的時候徐注意一些問題,比如async 方法需在其主體中具有 await 關(guān)鍵字,否則它們將永不暫停,接下來文字里將為大家舉例說明
    2021-09-09
  • 詳解C#中三個關(guān)鍵字params,Ref,out

    詳解C#中三個關(guān)鍵字params,Ref,out

    本文主要討論params關(guān)鍵字,ref關(guān)鍵字,out關(guān)鍵字。非常不錯,具有參考借鑒價值,需要的朋友參考下吧
    2017-05-05
  • C# WinForm實現(xiàn)自動更新程序的方法詳解

    C# WinForm實現(xiàn)自動更新程序的方法詳解

    這一篇就著重寫一下客戶端的代碼,客戶端主要實現(xiàn)的有:啟動后檢測本地的xml文件,然后發(fā)送到服務(wù)器獲取需要更新的文件以及版本列表,感興趣的小伙伴可以了解一下
    2022-10-10
  • 基于WPF實現(xiàn)彈幕效果的示例代碼

    基于WPF實現(xiàn)彈幕效果的示例代碼

    這篇文章主要為大家詳細介紹了如何利用WPF實現(xiàn)彈幕效果,文中的示例代碼講解詳細,對我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下
    2022-09-09
  • BootStrap mvcpager分頁樣式(get請求,刷新頁面)

    BootStrap mvcpager分頁樣式(get請求,刷新頁面)

    這篇文章主要介紹了BootStrap mvcpager分頁樣式(get請求,刷新頁面)的相關(guān)資料,通過引入相關(guān)文件,實現(xiàn)此功能,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-08-08
  • c#中task與thread的區(qū)別及使用講解

    c#中task與thread的區(qū)別及使用講解

    這篇文章主要介紹了c#中task與thread的區(qū)別及使用講解,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • C#實現(xiàn)較為實用的SQLhelper

    C#實現(xiàn)較為實用的SQLhelper

    這篇文章主要為大家詳細介紹了C#實現(xiàn)較為實用SQLhelper的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10

最新評論