亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#重寫DataGridView

 更新時間:2016年05月04日 16:09:52   投稿:lijiao  
這篇文章主要為大家詳細介紹了C#重寫DataGridView的相關資料,感興趣的小伙伴們可以參考一下

 本文實例為大家分享了C#重寫DataGridView的實例代碼,供大家參考,具體內容如下

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace CRD.WinUI.Editors
{
  public class DataGridView : System.Windows.Forms.DataGridView
  {
    private bool _CellColorOnchange=false;
    private Color cell_color = Color.Yellow;
    private bool shifouhuasanjiao = true;
    private Color color_grid = Color.FromArgb(236, 233, 216);
    bool click = false;
    public DataGridView()
    {
      this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
    }
    protected override void OnCreateControl()
    {
      this.EnableHeadersVisualStyles = false;
      this.ColumnHeadersDefaultCellStyle.BackColor = Color.FromArgb(236, 233, 216);
      this.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised;
      //this.ColumnHeadersHeight = 20;
      this.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
      this.ColumnHeadersDefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
      this.ColumnHeadersDefaultCellStyle.ForeColor = System.Drawing.SystemColors.WindowText;
      this.ColumnHeadersDefaultCellStyle.SelectionBackColor = System.Drawing.SystemColors.Highlight;
      this.ColumnHeadersDefaultCellStyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
      this.RowHeadersDefaultCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
      this.RowHeadersDefaultCellStyle.BackColor = Color.FromArgb(236, 233, 216);
      this.RowHeadersDefaultCellStyle.ForeColor = System.Drawing.SystemColors.WindowText;
      this.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Raised;
      this.DefaultCellStyle.SelectionBackColor = Color.DarkBlue;
      this.DefaultCellStyle.SelectionForeColor = Color.DarkSlateBlue;
      this.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
      //this.GridColor = Color.Silver;//表格點擊后顏色 表格線顏色
      this.BackgroundColor = System.Drawing.SystemColors.Window;
      this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.AllowUserToOrderColumns = true;
      this.AutoGenerateColumns = true;
      base.OnCreateControl();
    }
    Color defaultcolor;
    //移到單元格時的顏色
    protected override void OnCellMouseMove(DataGridViewCellMouseEventArgs e)
    {
      base.OnCellMouseMove(e);
      try
      {
        if (_CellColorOnchange)
          Rows[e.RowIndex].DefaultCellStyle.BackColor = cell_color;
      }
      catch (Exception)
      {
      }
    }
    //進入單元格時保存當前的顏色
    protected override void OnCellMouseEnter(DataGridViewCellEventArgs e)
    {
      base.OnCellMouseEnter(e);
      try
      {
        if (_CellColorOnchange)
          defaultcolor = Rows[e.RowIndex].DefaultCellStyle.BackColor;
      }
      catch (Exception)
      {
      }
    }
    //離開時還原顏色
    protected override void OnCellMouseLeave(DataGridViewCellEventArgs e)
    {
      base.OnCellMouseLeave(e);
      try
      {
        if (_CellColorOnchange)
          Rows[e.RowIndex].DefaultCellStyle.BackColor = defaultcolor;
      }
      catch (Exception)
      {
      }
    }
    public bool CellColorOnchange
    {
      get
      {
        return _CellColorOnchange;
      }
      set
      {
        _CellColorOnchange = value;
      }
    }
    public Color DefaultcolorSet
    {
      get
      {
        return cell_color;
      }
      set
      {
        cell_color = value;
      }
    }
    public bool Shifouhua_Sanjiao
    {
      get
      {
        return shifouhuasanjiao;
      }
      set
      {
        shifouhuasanjiao = value;
      }
    }
    public Color Content_Grid_color
    {
      get
      {
        return color_grid;
      }
      set
      {
        color_grid = value;
      }
    }
    private void InitializeComponent()
    {
      ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
      this.SuspendLayout();
      // 
      // DataGridView
      // 
      //this.RowTemplate.Height = 17;
       
      ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
      this.ResumeLayout(false);
    }
    //RowPostPaint
    protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
    {
      
      if (shifouhuasanjiao)
      {
        using (SolidBrush b = new SolidBrush(Color.Black))
        {
          Image image = global::CRD.WinUI.Properties.Resources.未標題_1;
          //e.Graphics.DrawString("►", e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 5, e.RowBounds.Location.Y + 4);
          //e.Graphics.DrawImageUnscaled(image, e.RowBounds.Location.X + 1, e.RowBounds.Location.Y + 2, 8, 13);
          if (click)
          if (e.RowIndex == this.CurrentRow.Index) {
            e.Graphics.DrawImageUnscaled(image, e.RowBounds.Location.X + 1, e.RowBounds.Location.Y + 2, 8, 13);
          }
           
        }
      }
       
       
      base.OnRowPostPaint(e);
    }
    
    
    protected override void OnRowPrePaint(DataGridViewRowPrePaintEventArgs e)
    {
      if (shifouhuasanjiao)
      {
        using (SolidBrush b = new SolidBrush(Color.Black))
        {
          Image image = global::CRD.WinUI.Properties.Resources.未標題_1;
          //e.Graphics.DrawString("►", e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 5, e.RowBounds.Location.Y + 4);
           //e.Graphics.DrawImageUnscaled(image, e.RowBounds.Location.X + 1, e.RowBounds.Location.Y + 2, 8, 13);
        }
      }
      base.OnRowPrePaint(e);
    }
    protected override void OnCellClick(DataGridViewCellEventArgs e)
    {
      if (e.RowIndex > -1&&this.CurrentRow.Index == e.RowIndex )
      {
        click = true;
      }
      base.OnCellClick(e);
    }
    protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
    {
      base.OnCellPainting(e);
       
      SolidBrush b = new SolidBrush(Color.FromArgb(236, 233, 216));
      Pen whitePen = new Pen(color_grid, 1);
      if (e.ColumnIndex == -1 && e.RowIndex == -1)
      {
        using (LinearGradientBrush brush = new LinearGradientBrush(e.CellBounds, Color.Gray,
          Color.Gray, LinearGradientMode.ForwardDiagonal))
        {
          e.Graphics.FillRectangle(b, e.CellBounds);
          Rectangle border = e.CellBounds;
          border.Offset(new Point(-1, -1));
          e.Graphics.DrawRectangle(Pens.Gray, border);
        }
        e.PaintContent(e.CellBounds);
        e.Handled = true;
      }
      else if (e.RowIndex == -1)
      {
        //標題行
        using (LinearGradientBrush brush = new LinearGradientBrush(e.CellBounds, Color.Silver,
          Color.Silver, LinearGradientMode.Vertical))
        {
          e.Graphics.FillRectangle(b, e.CellBounds);
          Rectangle border = e.CellBounds;
          border.Offset(new Point(-1, -1));
          e.Graphics.DrawRectangle(Pens.Silver, border);
          //e.Graphics.DrawRectangle(Pens.Black, border.X + 1, border.Y + 1, border.Width - 1, border.Height - 1);
        }
        e.PaintContent(e.CellBounds);
        e.Handled = true;
      }
      else if (e.ColumnIndex == -1)
      {
        //標題列
        using (LinearGradientBrush brush = new LinearGradientBrush(e.CellBounds, Color.Silver,
          Color.Silver, LinearGradientMode.Horizontal))
        {
           
          e.Graphics.FillRectangle(b, e.CellBounds);
          Rectangle border = e.CellBounds;
          border.Offset(new Point(-1, -1));
          e.Graphics.DrawRectangle(Pens.Silver, border);
          //e.Graphics.DrawRectangle(Pens.Black, border.X+1,border.Y+1,border.Width-1,border.Height-1);
          e.Graphics.DrawString("△", Font,b,e.CellBounds.X,e.CellBounds.Y);
        }
        e.PaintContent(e.CellBounds);
        e.Handled = true;
      }
      else
      {
        //Color.FromArgb(193, 193, 193)
        Rectangle border = e.CellBounds;
        border.Offset(new Point(-1, -1));
 
        e.Graphics.DrawRectangle(whitePen, border);
      }
    }
  }
}

以上就是本文的全部內容,希望對大家的學習有所幫助。

相關文章

  • c# 文件操作(移動,復制,重命名)

    c# 文件操作(移動,復制,重命名)

    這篇文章主要介紹了c# 如何對文件操作(移動,復制,重命名),幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2020-12-12
  • C#新特性之可空引用類型

    C#新特性之可空引用類型

    本文詳細講解了C#新特性之可空引用類型,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-02-02
  • C#怎樣才能實現窗體最小化到托盤呢?

    C#怎樣才能實現窗體最小化到托盤呢?

    C#怎樣才能實現窗體最小化到托盤呢?...
    2007-03-03
  • 使用Linq注意事項避免報錯的方法

    使用Linq注意事項避免報錯的方法

    這篇文章主要介紹了使用Linq注意事項避免報錯的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-01-01
  • C#如何實現子進程跟隨主進程關閉

    C#如何實現子進程跟隨主進程關閉

    多進程開發(fā)經常會遇到主進程關閉,子進程需要跟隨主進程一同關閉,比如調ffmpeg命令行實現的錄屏程序等,下面我們就來看看C#是如何實現子進程跟隨主進程關閉的吧
    2024-04-04
  • 詳解c# 切片語法糖

    詳解c# 切片語法糖

    這篇文章主要介紹了c# 切片語法糖的相關資料,幫助大家更好的理解和學習c#,感興趣的朋友可以了解下
    2020-09-09
  • 解析C#中@符號的幾種使用方法詳解

    解析C#中@符號的幾種使用方法詳解

    本篇文章是對C#中@符號的幾種使用方法進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • C#中enum和string的相互轉換

    C#中enum和string的相互轉換

    這篇文章主要介紹了C#中enum和string的相互轉換的相關資料,需要的朋友可以參考下
    2017-09-09
  • C#實現簡單點餐系統(tǒng)

    C#實現簡單點餐系統(tǒng)

    這篇文章主要為大家詳細介紹了C#實現簡單點餐系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-07-07
  • C# WinForm控件對透明圖片重疊時出現圖片不透明的簡單解決方法

    C# WinForm控件對透明圖片重疊時出現圖片不透明的簡單解決方法

    這篇文章主要介紹了C# WinForm控件對透明圖片重疊時出現圖片不透明的簡單解決方法,結合實例形式分析了WinForm圖片重疊后造成圖片不透明的原因與相應的解決方法,需要的朋友可以參考下
    2016-06-06

最新評論