首页 > 其他分享 >UI界面+treeviwe+dataGridView

UI界面+treeviwe+dataGridView

时间:2022-10-30 16:15:57浏览次数:38  
标签:sender void object System private dataGridView UI treeviwe using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp2
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();

treeView1.AllowDrop = true;
dataGridView1.AllowDrop = true;
treeView1.ItemDrag += TreeView1_ItemDrag;

}

private void dataGridView2_DragDrop(object sender, DragEventArgs e)
{
string cellvalue = e.Data.GetData(typeof(string)) as string;
Point cursorLocation = dataGridView1.PointToClient(new Point(e.X, e.Y));

System.Windows.Forms.DataGridView.HitTestInfo hittest = dataGridView1.HitTest(cursorLocation.X, cursorLocation.Y);
if (hittest.ColumnIndex != -1
&& hittest.RowIndex != -1)
{
dataGridView1[hittest.ColumnIndex, hittest.RowIndex].Value = cellvalue;
}
}

private void dataGridView2_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}

private void TreeView1_ItemDrag(object sender, ItemDragEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
TreeNode moveNode =(TreeNode) e.Item;
DoDragDrop(moveNode.Text+ moveNode.ImageIndex, DragDropEffects.Copy);
}
}

[DllImport("user32.dll")]
public static extern bool ReleaseCapture();

[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;


/// <summary>
/// 为了是主界面能够移动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
ReleaseCapture();
SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}

private void button2_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}

private void button3_Click(object sender, EventArgs e)
{
this.Close();
}

private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
SolidBrush back = new SolidBrush(Color.FromArgb(45, 45, 48));
SolidBrush white = new SolidBrush(Color.FromArgb(122, 193, 255));
Rectangle rec = tabControl1.GetTabRect(0);
e.Graphics.FillRectangle(back, rec);
Rectangle rec1 = tabControl1.GetTabRect(1);
e.Graphics.FillRectangle(back, rec1);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
for (int i = 0; i < tabControl1.TabPages.Count; i++)
{
Rectangle rec2 = tabControl1.GetTabRect(i);
e.Graphics.DrawString(tabControl1.TabPages[i].Text, new Font("微软雅黑", 9), white, rec2, sf);
}
}

private void button4_Click(object sender, EventArgs e)
{
if(rowIndex>=0)
{
this.dataGridView1.Rows.Insert(rowIndex);
this.dataGridView1.Rows[rowIndex].Cells[0].Value = "";
}

}
int rowIndex = 0;
private void button5_Click(object sender, EventArgs e)
{

if (!this.dataGridView1.Rows[rowIndex].IsNewRow)
{
this.dataGridView1.Rows.RemoveAt(rowIndex);
}
}

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
rowIndex = e.RowIndex;
}

private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < progressBar1.Maximum)
{
progressBar1.Value += 4;
}

}
}
class MyProgressBar : ProgressBar //新建一个MyProgressBar类,它继承了ProgressBar的所有属性与方法
{
public MyProgressBar()
{
base.SetStyle(ControlStyles.UserPaint, true);//使控件可由用户自由重绘
}
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush brush = null;
Rectangle bounds = new Rectangle(0, 0, base.Width, base.Height);
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 1, 1, bounds.Width - 2, bounds.Height - 2);//此处完成背景重绘,并且按照属性中的BackColor设置背景色
bounds.Height -= 4;
bounds.Width = ((int)(bounds.Width * (((double)base.Value) / ((double)base.Maximum)))) - 4;//是的进度条跟着ProgressBar.Value值变化
brush = new SolidBrush(this.ForeColor);
e.Graphics.FillRectangle(brush, 2, 2, bounds.Width, bounds.Height);//此处完成前景重绘,依旧按照Progressbar的属性设置前景色
}
}
}

标签:sender,void,object,System,private,dataGridView,UI,treeviwe,using
From: https://www.cnblogs.com/xiaohuzi007/p/16841474.html

相关文章