Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > ช่วยผมด้วยครับถามเรื่องใช้ function Rectangle>Event Cell painting>datagridview:: โปรแกรม vs2019 ครับ หัดเขียนครับ มี 2 คำถามครับ



 

ช่วยผมด้วยครับถามเรื่องใช้ function Rectangle>Event Cell painting>datagridview:: โปรแกรม vs2019 ครับ หัดเขียนครับ มี 2 คำถามครับ

 



Topic : 135685



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์




อันนี้คำถามแรกครับ

ใน Event Cell painting >Datagridview
e.Graphics.FillRectangle(new Solidbrush(Color.LightGray),50);
ถ้าผมอยากจะใช้ e.Graphics.FillRectangle ในปุ่ม Button ต้องใส่คำสั่งแทนว่าอะไรหรอครับ
'====================================================================


ต่อมาอันนี้เป็นปัญหา ไม่รู้จะแก้ยังไงครับ
คือผมใช้ Rectangle ครับ แต่มีหลายหัว Column ครับ ต้องมี scollbar เลื่อนไปๆ มาๆ + กับใช้ Rectangle
เวลาผมเลื่อนไป มาทำให้ ตัว rectangle มันหายอ่ะ ครับ ต้องเอา เมาส์ ไปส่องถึงจะขึ้นมาใหม่ มีวิธีแก้ไหมครับ

1. โหลด Form ขึ้นมาครับ
LoadFile

2.ขยับ Scroll Bar ครับ แล้วก็ขยับกับไปตำแหน่งเดิม
ขยับscroll bar
ขยับกับมาที่เดิม
3. ต้องเอาเมาส์ไปส่องไล่ตาม cell ถึงขึ้น
ส่อง



Tag : .NET, C#, Windows







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2020-11-02 11:47:37 By : tuipoktui View : 681 Reply : 2
 

 

No. 1



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์


อันนี้ Code ครับ

private void gidDetail_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
int heightOffset = -5;
int widthOffset = -1;
int xOffset = -1;
int yOffset = 4;

string[] hmerge = { "ขอบ5+V2X(บน)+V2(ล่าง)","ขอบ5+V3A(บน)+V3A(ล่าง)","ขอบ7+V2X(บน)+V2X(ล่าง)","ขอบ7+V2X(บน)+V3A(ล่าง)","ขอบ7+V3A(บน)+V3A(ล่าง)","ขอบPocket+V3A(บน)+V3A(ล่าง)",
"มุม7+V3A(บน)+V3A(ล่าง)","ยิงบ๊อก(ขอบ5)+V3A(บน)","ยิงบ๊อก(ขอบ7)+V3A(บน)","หุ้มโกลด์สปริง", "รวม"
};

//int columnIndex = 7;
//Rectangle headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnIndex, 0, true);
//int xCord = headerCellRectangle.Location.X + xOffset;
//int yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
//int mergedHeaderWidth = gidDetail.Columns[columnIndex].Width + gidDetail.Columns[columnIndex + 5].Width + widthOffset;
//Rectangle mergedHeaderRect = new Rectangle(xCord, yCord, mergedHeaderWidth, headerCellRectangle.Height + heightOffset);
//e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);


for (int xcol = 0; xcol < hmerge.Count(); xcol++)
{
int columnx = 0;
switch (xcol)
{
case 0:
columnx = 7;
Rectangle headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnx, 0, true);
int mergedHeaderWidth = gidDetail.Columns[columnx].Width * 5 + widthOffset;
int xCord = headerCellRectangle.Location.X + xOffset;
int yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
float xcordfont = e.Graphics.MeasureString(hmerge[0].Remove(hmerge[0].Length - 1), Font).Width;


int xcordfontF = (mergedHeaderWidth - (int)Math.Round(xcordfont)) / 2;


Rectangle mergedHeaderRect = new Rectangle(xCord, yCord - 2, mergedHeaderWidth + 2, headerCellRectangle.Height + 2 + heightOffset);
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);

e.Graphics.DrawString(hmerge[0], gidDetail.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, xCord + xcordfontF + 2, yCord + 3);
break;
case 1:
columnx = 12;
headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnx, 0, true);
mergedHeaderWidth = gidDetail.Columns[columnx].Width * 5 + widthOffset;
xCord = headerCellRectangle.Location.X + xOffset;
yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
xcordfont = e.Graphics.MeasureString(hmerge[1].Remove(hmerge[1].Length - 1), Font).Width;


xcordfontF = (mergedHeaderWidth - (int)Math.Round(xcordfont)) / 2;

mergedHeaderRect = new Rectangle(xCord, yCord - 2, mergedHeaderWidth + 2, headerCellRectangle.Height + 2 + heightOffset);
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);

e.Graphics.DrawString(hmerge[1], gidDetail.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, xCord + xcordfontF + 2, yCord + 3);
break;
case 2:
columnx = 17;
headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnx, 0, true);
mergedHeaderWidth = gidDetail.Columns[columnx].Width * 5 + widthOffset;
xCord = headerCellRectangle.Location.X + xOffset;
yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
xcordfont = e.Graphics.MeasureString(hmerge[2].Remove(hmerge[2].Length - 1), Font).Width;


xcordfontF = (mergedHeaderWidth - (int)Math.Round(xcordfont)) / 2;

mergedHeaderRect = new Rectangle(xCord, yCord - 2, mergedHeaderWidth + 2, headerCellRectangle.Height + 2 + heightOffset);
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);

e.Graphics.DrawString(hmerge[2], gidDetail.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, xCord + xcordfontF + 2, yCord + 3);
break;
case 3:
columnx = 22;
headerCellRectangle = gidDetail.GetCellDisplayRectangle(columnx, 0, true);
mergedHeaderWidth = gidDetail.Columns[columnx].Width * 5 + widthOffset;
xCord = headerCellRectangle.Location.X + xOffset;
yCord = headerCellRectangle.Location.Y - headerCellRectangle.Height + yOffset;
xcordfont = e.Graphics.MeasureString(hmerge[3].Remove(hmerge[3].Length - 1), Font).Width;


xcordfontF = (mergedHeaderWidth - (int)Math.Round(xcordfont)) / 2;

mergedHeaderRect = new Rectangle(xCord, yCord - 2, mergedHeaderWidth + 2, headerCellRectangle.Height + 2 + heightOffset);
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray), mergedHeaderRect);

e.Graphics.DrawString(hmerge[3], gidDetail.ColumnHeadersDefaultCellStyle.Font, Brushes.Black, xCord + xcordfontF + 2, yCord + 3);
break;

}


}



}






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-11-02 11:50:49 By : tuipoktui
 


 

No. 2



โพสกระทู้ ( 1,458 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Blogger

วิธีที่ดีที่สุด (ยืดหยุ่นและง่าย) คือ HTML + WebView2
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-11-23 10:44:40 By : PhrayaDev
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยผมด้วยครับถามเรื่องใช้ function Rectangle>Event Cell painting>datagridview:: โปรแกรม vs2019 ครับ หัดเขียนครับ มี 2 คำถามครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่