分三部分:icoform 和Main、配置文件 :ShowInfo.xml;
icoform:靠桌面邊緣自動吸附,雙擊顯示Main.
//===============================icoform===========
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
public partial class icoform : Form
{
public icoform()
{
InitializeComponent();
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; //最左座標
public int Top; //最上座標
public int Right; //最右座標
public int Bottom; //最下座標
}
Point mouseOff;//鼠標位置變量
bool leftFlag;//是否爲左鍵
private void pictureBox1_DoubleClick(object sender, EventArgs e)
{
ma.Show();
}
Main ma = new Main();
private void icoform_Load(object sender, EventArgs e)
{//
// 窗體在右上角
//this.Top = 150;
//this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
this.Hide();
string pr = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
if (System.Diagnostics.Process.GetProcessesByName(pr).GetUpperBound(0) > 0)
{
// MessageBox.Show("程序已經在運行");
Application.ExitThread();
Application.Exit();
}
this.Width = 82;
this.Height = 82;
this.Top = 150;
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
}
private void timer1_Tick(object sender, EventArgs e)
{
try
{
int width = 0;
int height = 0;
foreach (Process thispr in Process.GetProcesses())
{
if (thispr.ProcessName.Contains("vivoTestStand201"))
{
RECT rect = new RECT();
GetWindowRect(thispr.MainWindowHandle, ref rect);
width = rect.Right;//窗口的寬度
height = rect.Bottom;//窗口的高度
this.Top = height - 300;
this.Left = width;
this.Show();
}
}
}
catch (Exception)
{
throw;
}
}
private void pictureBox1_MouseEnter(object sender, EventArgs e)
{
//================================
if (this.Left < 0)
{
this.Left = 0;
}
if (this.Top < 0)
{
this.Top = 0;
}
if (this.Right > Screen.PrimaryScreen.WorkingArea.Width)//右
{
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
}
if (this.Bottom > Screen.PrimaryScreen.WorkingArea.Height)
{
this.Top = 150;
this.Left = Screen.PrimaryScreen.WorkingArea.Width - this.Width;
}
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
//離開
if ( this.Left < 0 || this.Left ==0)
{
this.Left = -70;
}
if (this.Top < 0 || this.Top == 0)
{
this.Top =-70;
}
if (this.Right > Screen.PrimaryScreen.WorkingArea.Width || this.Right ==Screen.PrimaryScreen.WorkingArea.Width)//右
{
this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5;
}
if (this.Bottom > Screen.PrimaryScreen.WorkingArea.Height || this.Bottom == Screen.PrimaryScreen.WorkingArea.Height)
{
this.Top = 150;
this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5;
}
if ( this.Top == 150)
{
this.Top = 150;
this.Left = Screen.PrimaryScreen.WorkingArea.Width - 5;
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y);//得到的變量
leftFlag = true;//左鍵按下是設置爲Trun
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y);//設置移動後位置
Location = mouseSet;
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;
}
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
ma.Show();
}
private void 退出程序ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.ExitThread();
Application.Exit();
}
}
//===============================Main===========
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using TabConWinForm;
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
int y = 0;//設置選項卡數量
//Point mouseOff;//鼠標位置變量
//bool leftFlag;//是否爲左鍵
private void Form1_Load(object sender, EventArgs e)
{
this.tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
this.tabControl1.DrawItem += new DrawItemEventHandler(this.tabControl1_DrawItem);
//處理dataGridView結構樣式
DataTable dtt = new DataTable();
dtt.Columns.Add("機型", typeof(string));
dtt.Columns.Add("平臺", typeof(string));
dtt.Columns.Add("芯片類型", typeof(string));
tabControl1.TabPages.Clear();//清除所有默認數據
////將XML文件加載進來
XmlDocument doc2 = new XmlDocument();
doc2.Load("ShowInfo.xml");
//獲取根節點
XmlElement root2 = doc2.DocumentElement;
//獲取子節點
XmlNodeList pnodes = root2.ChildNodes;
//使用foreach循環讀出集合
foreach (XmlNode node in pnodes)
{
if (node.Name.Contains("Fixture"))
{
DataTable dt = new DataTable();
// dt.Columns.Add("Item", typeof(string));
dt.Columns.Add("ItemName", typeof(string));
// dt.Columns.Add("type", typeof(string));
dt.Columns.Add("Text", typeof(string));
dt.Columns.Add("Comments", typeof(string));
foreach (XmlNode nodee in node)
{
// string nnameee = nodee.Name;
string nname2 = ((XmlElement)nodee).GetAttribute("ItemName");
// string nname3 = ((XmlElement)nodee).GetAttribute("type");
string nname4 = ((XmlElement)nodee).GetAttribute("Comments");
string nname5 = nodee.InnerText;
dt.Rows.Add(new object[] { nname2, nname5, nname4 });
}
TabForm tabwin = new TabForm(dt);
tabwin.FormBorderStyle = FormBorderStyle.None;
tabwin.Dock = DockStyle.Fill;
tabwin.TopLevel = false;
tabControl1.TabPages.Add(node.Name);//添加多一個選項卡
tabControl1.TabPages[y].Controls.Add(tabwin);
tabControl1.TabPages[y].Text = node.Name;
tabwin.Show();
tabControl1.SelectedIndex = y;
//tabControl1.TabPages[y].BackColor = Color.YellowGreen;
y++;
}
if (!node.Name.Contains("Fixture"))
{
//foreach (XmlNode nod in node)
//{
if (node.Name.Contains("PhoneModel"))
{
string nnameee = node.InnerText;
string nname2 = ((XmlElement)node).GetAttribute("Platform");
string nname3 = ((XmlElement)node).GetAttribute("Scheme");
dtt.Rows.Add(new object[] { nnameee, nname2, nname3 });
dtt.Rows.Add(new object[] { " ", " ", " " });
}
if (node.Name.Contains("Item"))
{
string nnameee = node.InnerText;
string nname2 = ((XmlElement)node).GetAttribute("ItemName");
string nname3 = ((XmlElement)node).GetAttribute("Comments");
dtt.Rows.Add(new object[] { nname2, nnameee, nname3 });
}
}
}
dataGridView1.DataSource = dtt;
dataGridView1.RowHeadersVisible = false;//取消最左邊列
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;//列頭內容全鋪滿
// this.dataGridView1.DefaultCellStyle.Font = new Font("微軟雅黑", 14);
splitContainer1.IsSplitterFixed = true;//禁止手動手動splitContainer
this.dataGridView1.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//設置行居中
this.dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//列頭居中
dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.Automatic;//列頭排列禁用
dataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.Automatic;//列頭排列禁用
dataGridView1.Columns[2].SortMode = DataGridViewColumnSortMode.Automatic;//列頭排列禁用
dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;//列頭排列禁用
dataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;//列頭排列禁用
dataGridView1.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;//列頭排列禁用
this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;//禁止改變datagirdview列頭寬度和行頭高度
dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;//禁止改變datagirdview列頭寬度和行頭高度
dataGridView1.AllowUserToResizeRows = false;//禁用行高調整
DataGridViewRow row = dataGridView1.Rows[0];
row.Height = 35;
DataGridViewRow roww = dataGridView1.Rows[1];
roww.Height = 12;
DataGridViewRow rows = dataGridView1.Rows[2];
rows.Height = 35;
dataGridView1.Rows[1].Cells[0].Style.BackColor = SystemColors.ControlDark;
dataGridView1.Rows[1].Cells[0].ReadOnly=true;
dataGridView1.Rows[1].Cells[1].Style.BackColor = SystemColors.ControlDark;
dataGridView1.Rows[1].Cells[1].ReadOnly = true;
dataGridView1.Rows[1].Cells[2].Style.BackColor = SystemColors.ControlDark;
dataGridView1.Rows[1].Cells[2].ReadOnly = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
//tabControl1.TabPages[y].BackColor = Color.YellowGreen;
try
{
//=============================================
int i = tabControl1.SelectedIndex;
int y = 0;
tabControl1.TabPages.Clear();//清除所有默認數據
dataGridView1.DataSource = null;
//處理dataGridView結構樣式
DataTable dtt = new DataTable();
dtt.Columns.Add("機型", typeof(string));
dtt.Columns.Add("平臺", typeof(string));
dtt.Columns.Add("芯片類型", typeof(string));
tabControl1.TabPages.Clear();//清除所有默認數據
////將XML文件加載進來
XmlDocument doc2 = new XmlDocument();
doc2.Load("ShowInfo.xml");
//獲取根節點
XmlElement root2 = doc2.DocumentElement;
//獲取子節點
XmlNodeList pnodes = root2.ChildNodes;
//使用foreach循環讀出集合
foreach (XmlNode node in pnodes)
{
if (node.Name.Contains("Fixture"))
{
DataTable dt = new DataTable();
// dt.Columns.Add("Item", typeof(string));
dt.Columns.Add("ItemName", typeof(string));
// dt.Columns.Add("type", typeof(string));
dt.Columns.Add("Text", typeof(string));
dt.Columns.Add("Comments", typeof(string));
foreach (XmlNode nodee in node)
{
// string nnameee = nodee.Name;
string nname2 = ((XmlElement)nodee).GetAttribute("ItemName");
// string nname3 = ((XmlElement)nodee).GetAttribute("type");
string nname4 = ((XmlElement)nodee).GetAttribute("Comments");
string nname5 = nodee.InnerText;
dt.Rows.Add(new object[] { nname2, nname5, nname4 });
}
TabForm tabwin = new TabForm(dt);
tabwin.FormBorderStyle = FormBorderStyle.None;
tabwin.Dock = DockStyle.Fill;
tabwin.TopLevel = false;
tabControl1.TabPages.Add(node.Name);//添加多一個選項卡
tabControl1.TabPages[y].Controls.Add(tabwin);
tabControl1.TabPages[y].Text = node.Name;
tabwin.Show();
tabControl1.SelectedIndex = i;
tabControl1.TabPages[y].BackColor = Color.YellowGreen;
y++;
}
if (!node.Name.Contains("Fixture"))
{
//foreach (XmlNode nod in node)
//{
if (node.Name.Contains("PhoneModel"))
{
string nnameee = node.InnerText;
string nname2 = ((XmlElement)node).GetAttribute("Platform");
string nname3 = ((XmlElement)node).GetAttribute("Scheme");
dtt.Rows.Add(new object[] { nnameee, nname2, nname3 });
dtt.Rows.Add(new object[] { " ", " ", " " });
}
if (node.Name.Contains("Item"))
{
string nnameee = node.InnerText;
string nname2 = ((XmlElement)node).GetAttribute("ItemName");
string nname3 = ((XmlElement)node).GetAttribute("Comments");
dtt.Rows.Add(new object[] { nnameee, nname2, nname3 });
}
}
}
dataGridView1.DataSource = dtt;
dataGridView1.RowHeadersVisible = false;//取消最左邊列
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;//列頭內容全鋪滿
// this.dataGridView1.DefaultCellStyle.Font = new Font("微軟雅黑", 14);
splitContainer1.IsSplitterFixed = true;//禁止手動手動splitContainer
this.dataGridView1.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//設置行居中
this.dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//列頭居中
dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.Automatic;//列頭排列禁用
dataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.Automatic;//列頭排列禁用
dataGridView1.Columns[2].SortMode = DataGridViewColumnSortMode.Automatic;//列頭排列禁用
dataGridView1.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;//列頭排列禁用
dataGridView1.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;//列頭排列禁用
dataGridView1.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;//列頭排列禁用
this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;//禁止改變datagirdview列頭寬度和行頭高度
dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;//禁止改變datagirdview列頭寬度和行頭高度
dataGridView1.AllowUserToResizeRows = false;//禁用行高調整
DataGridViewRow row = dataGridView1.Rows[0];
row.Height = 35;
DataGridViewRow roww = dataGridView1.Rows[1];
roww.Height = 12;
DataGridViewRow rows = dataGridView1.Rows[2];
rows.Height = 35;
dataGridView1.Rows[1].Cells[0].Style.BackColor = SystemColors.ControlDark;
dataGridView1.Rows[1].Cells[0].ReadOnly = true;
dataGridView1.Rows[1].Cells[1].Style.BackColor = SystemColors.ControlDark;
dataGridView1.Rows[1].Cells[1].ReadOnly = true;
dataGridView1.Rows[1].Cells[2].Style.BackColor = SystemColors.ControlDark;
dataGridView1.Rows[1].Cells[2].ReadOnly = true;
}
catch (Exception)
{
throw;
}
}
private void 最小化ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
}
private void tabPage1_MouseDown(object sender, MouseEventArgs e)
{
}
private void tabPage1_MouseMove(object sender, MouseEventArgs e)
{
}
private void tabPage1_MouseUp(object sender, MouseEventArgs e)
{
}
private void tabControl1_MouseDown(object sender, MouseEventArgs e)
{
//if (e.Button == MouseButtons.Left)
//{
// mouseOff = new Point(-e.X, -e.Y);//得到的變量
// leftFlag = true;//左鍵按下是設置爲Trun
//}
}
private void tabControl1_MouseMove(object sender, MouseEventArgs e)
{
//if (leftFlag)
//{
// Point mouseSet = Control.MousePosition;
// mouseSet.Offset(mouseOff.X, mouseOff.Y);//設置移動後位置
// Location = mouseSet;
//}
}
private void tabControl1_MouseUp(object sender, MouseEventArgs e)
{
//if (leftFlag)
//{
// leftFlag = false;
//}
}
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
// notifyIcon1.ShowBalloonTip(1000, "已最小化", "需要顯示請重新雙擊!", ToolTipIcon.Info);
}
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
Font fntTab;
Brush bshBack,bshFore;
if (e.Index == this.tabControl1.SelectedIndex) //當前Tab頁的樣式
{
fntTab = new Font(e.Font, FontStyle.Bold);
bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.Control, SystemColors.Control, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
bshFore = Brushes.YellowGreen;
}
else //其餘Tab頁的樣式
{
fntTab = e.Font;
bshFore = new SolidBrush(Color.Black);
}
//畫樣式
string tabName = this.tabControl1.TabPages[e.Index].Text;
StringFormat sftTab = new StringFormat();
Rectangle recTab = e.Bounds;
recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);
}
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
}
//private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
//{
// //繪畫
// //橫向合併
// if (e.ColumnIndex >= 0 && this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "機型" && e.RowIndex >= 0)
// {
// using (
// Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
// backColorBrush = new SolidBrush(e.CellStyle.BackColor))
// {
// using (Pen gridLinePen = new Pen(gridBrush))
// {
// // 擦除原單元格背景
// e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
// /****** 繪製單元格相互間隔的區分線條,datagridview自己會處理左側和上邊緣的線條,因此只需繪製下邊框和和右邊框
// DataGridView控件繪製單元格時,不繪製左邊框和上邊框,共用左單元格的右邊框,上一單元格的下邊框*****/
// //不是最後一列且單元格的值不爲null
// if (e.ColumnIndex < this.dataGridView1.ColumnCount - 1 && this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value != null)
// {
// if (e.Value.ToString() != this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value.ToString())
// {
// //右側的線
// e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top,
// e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
// ////繪製值
// if (e.Value != null)
// {
// e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,
// Brushes.Crimson, e.CellBounds.X + 2,
// e.CellBounds.Y + 2, StringFormat.GenericDefault);
// }
// }
// //若與下一單元格值相同
// else
// {
// //背景顏色
// //e.CellStyle.BackColor = Color.LightPink; //僅在CellFormatting方法中可用
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Wheat ;
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Style.BackColor = Color.Wheat;
// //只讀(以免雙擊單元格時顯示值)
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ReadOnly = true;
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].ReadOnly = true;
// }
// }
// else
// {
// //右側的線
// e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top,
// e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
// ////繪製值
// //if (e.Value != null)
// //{
// // e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,
// // Brushes.Crimson, e.CellBounds.X + 2,
// // e.CellBounds.Y + 2, StringFormat.GenericDefault);
// //}
// }
// //下邊緣的線
// e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1,
// e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
// e.Handled = true;
// }
// }
// }
// //橫向合併
// if (e.ColumnIndex >= 0 && this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "平臺" && e.RowIndex >= 0)
// {
// using (
// Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
// backColorBrush = new SolidBrush(e.CellStyle.BackColor))
// {
// using (Pen gridLinePen = new Pen(gridBrush))
// {
// // 擦除原單元格背景
// e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
// /****** 繪製單元格相互間隔的區分線條,datagridview自己會處理左側和上邊緣的線條,因此只需繪製下邊框和和右邊框
// DataGridView控件繪製單元格時,不繪製左邊框和上邊框,共用左單元格的右邊框,上一單元格的下邊框*****/
// //不是最後一列且單元格的值不爲null
// if (e.ColumnIndex < this.dataGridView1.ColumnCount - 1 && this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value != null)
// {
// if (e.Value.ToString() != this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value.ToString())
// {
// //右側的線
// e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top,
// e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
// //繪製值
// if (e.Value != null)
// {
// e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,
// Brushes.Crimson, e.CellBounds.X + 2,
// e.CellBounds.Y + 2, StringFormat.GenericDefault);
// }
// }
// //若與下一單元格值相同
// else
// {
// //背景顏色
// //e.CellStyle.BackColor = Color.LightPink; //僅在CellFormatting方法中可用
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.LightPink;
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Style.BackColor = Color.LightPink;
// //只讀(以免雙擊單元格時顯示值)
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ReadOnly = true;
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].ReadOnly = true;
// }
// }
// else
// {
// //右側的線
// e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top,
// e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
// }
// //下邊緣的線
// e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1,
// e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
// e.Handled = true;
// }
// }
// }
// //橫向合併
// if (e.ColumnIndex >= 0 && this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "芯片類型" && e.RowIndex >= 0)
// {
// using (
// Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
// backColorBrush = new SolidBrush(e.CellStyle.BackColor))
// {
// using (Pen gridLinePen = new Pen(gridBrush))
// {
// // 擦除原單元格背景
// e.Graphics.FillRectangle(backColorBrush, e.CellBounds);
// /****** 繪製單元格相互間隔的區分線條,datagridview自己會處理左側和上邊緣的線條,因此只需繪製下邊框和和右邊框
// DataGridView控件繪製單元格時,不繪製左邊框和上邊框,共用左單元格的右邊框,上一單元格的下邊框*****/
// //不是最後一列且單元格的值不爲null
// if (e.ColumnIndex < this.dataGridView1.ColumnCount - 1 && this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value != null)
// {
// if (e.Value.ToString() != this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value.ToString())
// {
// //右側的線
// e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top,
// e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
// //繪製值
// if (e.Value != null)
// {
// e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,
// Brushes.Crimson, e.CellBounds.X + 2,
// e.CellBounds.Y + 2, StringFormat.GenericDefault);
// }
// }
// //若與下一單元格值相同
// else
// {
// //背景顏色
// //e.CellStyle.BackColor = Color.LightPink; //僅在CellFormatting方法中可用
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.LightPink;
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Style.BackColor = Color.LightPink;
// //只讀(以免雙擊單元格時顯示值)
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ReadOnly = true;
// this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].ReadOnly = true;
// }
// }
// else
// {
// //右側的線
// e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top,
// e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
// //繪製值
// if (e.Value != null)
// {
// e.Graphics.DrawString(e.Value.ToString(), e.CellStyle.Font,
// Brushes.Crimson, e.CellBounds.X + 2,
// e.CellBounds.Y + 2, StringFormat.GenericDefault);
// }
// }
// //下邊緣的線
// e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1,
// e.CellBounds.Right - 1, e.CellBounds.Bottom - 1);
// e.Handled = true;
// }
// }
// }
//}
// int?是搜索一種類型(可空類型),普通的int不能爲null,而用int?,其值可以爲null
//private int? nextrow = null;
//private int? nextcol = null;
//在CellPainting方法後調用
private void dataGridView1_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e)
{
/*
//列標示
if (e.ColumnIndex >= 0 && this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "PARENTID" && e.RowIndex >= 0)
{
//若與下一行同列單元格值相同則修改設置
if (e.RowIndex < this.dataGridView1.RowCount - 1 && this.dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value != null)
{
if (e.Value.ToString() == this.dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString())
{
e.CellStyle.BackColor = Color.LightPink;
this.dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Style.BackColor = Color.LightPink;
this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ReadOnly = true;
//this.dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].ReadOnly = true;
}
}
}
*/
/*
//行標示
if (e.ColumnIndex >= 0 && this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "PHONE1" && e.RowIndex >= 0)
{
//若與同行下一列單元格值相同則修改設置
if (e.ColumnIndex != this.dataGridView1.ColumnCount - 1 && this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value != null)
{
if (e.Value.ToString() == this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value.ToString())
{
e.CellStyle.BackColor = Color.LightBlue;
this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Style.BackColor = Color.LightPink;
this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ReadOnly = true;
//this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].ReadOnly = true;
}
}
}
*/
}
}
//=========ShowInfo.xml內容================
<ShowInfoConfig>
<PhoneModel Platform="SDM845" Scheme="高通">PD1821A</PhoneModel>
<Item ItemName="MTKDBFile" type="showPath" Comments="this is MTK DB file Path ,double click can open Path">C:\Program Files\vivoTestStand\CFG\40\cddd.db</Item>
<Fixture0>
<Item ItemName="FixID" type="showString" Comments="Fix ID " >2019newFixID</Item>
<Item ItemName="ForceCheckTime" type="showTime" TimeInterval="72" Comments="ForceCheckTime " >2018-11-7 22:15:20</Item>
</Fixture0>
<Fixture1>
<Item ItemName="FixID" type="showString" Comments="Fix ID " >vivo2018newFixID</Item>
<Item ItemName="ForceCheckTime" type="showTime" TimeInterval="72" Comments="ForceCheckTime " >2018-11-7 22:15:20</Item>
</Fixture1>
</ShowInfoConfig>