Click here to Skip to main content
15,903,388 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Passing a list of structures from managed c++ to c# Pin
slkr17126-Sep-07 20:55
slkr17126-Sep-07 20:55 
Questionusing unmanaged dlls asserts Pin
dedil26-Sep-07 1:13
dedil26-Sep-07 1:13 
QuestionWhat is resposible for Painting DataGridView Pin
BuckBrown24-Sep-07 12:33
BuckBrown24-Sep-07 12:33 
AnswerRe: What is resposible for Painting DataGridView Pin
Luc Pattyn24-Sep-07 14:15
sitebuilderLuc Pattyn24-Sep-07 14:15 
GeneralRe: What is resposible for Painting DataGridView Pin
BuckBrown25-Sep-07 6:05
BuckBrown25-Sep-07 6:05 
GeneralRe: What is resposible for Painting DataGridView Pin
BuckBrown25-Sep-07 7:19
BuckBrown25-Sep-07 7:19 
GeneralRe: What is resposible for Painting DataGridView Pin
BuckBrown25-Sep-07 9:26
BuckBrown25-Sep-07 9:26 
GeneralRe: What is resposible for Painting DataGridView [modified] Pin
Luc Pattyn26-Sep-07 7:31
sitebuilderLuc Pattyn26-Sep-07 7:31 
Hi Buck,

I am unfamiliar with the DGV control, but I performed some experiments with a Panel
and drawing/dispatching events myself. This is the C# code involved:

using System;
using System.Drawing;
using System.Windows.Forms;

namespace wafer {
	class Chip {
		public Rectangle rect;
		public bool inked;
		public string name;

		public void Paint(Graphics g) {
			if(inked) g.FillRectangle(Brushes.Red, rect);
			g.DrawRectangle(Pens.Black, rect);
		}
	}

	class WaferPanel : Panel {
		private int hor;
		private int vert;
		private Chip[,] chips;
		private Random rand=new Random();
		private static Font font=new Font("Courier New", 7);

		public WaferPanel(int hor, int vert, bool doubleBuffered) {
			// make double-buffered
			if(doubleBuffered) {
				SetStyle(ControlStyles.AllPaintingInWmPaint|
				ControlStyles.OptimizedDoubleBuffer|
				ControlStyles.UserPaint, true);
			}
			log("WaferPanel.ctor");
			this.hor=hor;
			this.vert=vert;
			chips=new Chip[hor,vert];
			for(int i=0; i< hor; i++) {
				for(int j=0; j< vert; j++) {
					Chip c=new Chip();
					chips[i, j]=c;
					c.inked=rand.Next(10)==0;	// 10% inked at random
					c.name=i.ToString()+","+j.ToString();
				}
			}
			BackColor=Color.White;
		}

		private void log(string s) { Console.WriteLine(s); }

		protected override void OnResize(EventArgs e) {
			int W=Width;
			int H=Height;
			log("WaferPanel.OnResize: W="+W+"  H="+H);
			int w=(W-100)/hor;
			int h=(H-100)/vert;
			if(w<4) w=4;
			if(h<4) h=4;
			log("WaferPanel.OnResize: w="+w+"  h="+h);
			int x0=(W-w*hor)/2;
			int y0=(H-h*vert)/2;
			log("WaferPanel.OnResize: x0="+x0+"  y0="+y0);
			for(int i=0; i< hor; i++) {
				for(int j=0; j< vert; j++) {
					Chip c=chips[i, j];
					c.rect=new Rectangle(x0+i*w, y0+j*h, w-3, h-3);
				}
			}
		}

		protected override void OnPaint(PaintEventArgs e) {
			log("WaferPanel.OnPaint");
			Graphics g=e.Graphics;

			for(int i=0; i< hor; i++) {
				Chip c=chips[i, 0];
				g.DrawString(i.ToString(), font, Brushes.Black, c.rect.X, 10);
			}
			for(int j=0; j< vert; j++) {
				Chip c=chips[0, j];
				g.DrawString(j.ToString(), font, Brushes.Black, 10, c.rect.Y);
			}

			for(int i=0; i< hor; i++) {
				for(int j=0; j< vert; j++) {
					Chip c=chips[i, j];
					c.Paint(g);
				}
			}
		}

		protected override void OnMouseClick(MouseEventArgs e) {
			Point pt=new Point(e.X,e.Y);
			Chip hit=null;
			foreach(Chip c in chips) {
				if(c.rect.Contains(pt)) hit=c;
			}
			if(hit==null) {
				Console.Beep();
			} else {
				log("WaferPanel.OnMouseClick hit "+hit.name);
				hit.inked=!hit.inked;
				Invalidate(hit.rect);
			}
		}
	}
}


Hope this helps.



-- modified at 13:52 Wednesday 26th September, 2007 (HTML repairs)

Luc Pattyn [Forum Guidelines] [My Articles]


this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google


GeneralRe: What is resposible for Painting DataGridView Pin
Luc Pattyn26-Sep-07 10:04
sitebuilderLuc Pattyn26-Sep-07 10:04 
AnswerRe: What is resposible for Painting DataGridView Pin
led mike25-Sep-07 5:01
led mike25-Sep-07 5:01 
GeneralRe: What is resposible for Painting DataGridView Pin
BuckBrown25-Sep-07 6:10
BuckBrown25-Sep-07 6:10 
GeneralRe: What is resposible for Painting DataGridView Pin
BuckBrown25-Sep-07 7:19
BuckBrown25-Sep-07 7:19 
AnswerRe: What is resposible for Painting DataGridView Pin
KarstenK26-Sep-07 4:02
mveKarstenK26-Sep-07 4:02 
QuestionReading and writing to a named pipe C, C++, C# Pin
higgsbo23-Sep-07 7:41
higgsbo23-Sep-07 7:41 
AnswerRe: Reading and writing to a named pipe C, C++, C# Pin
led mike24-Sep-07 4:57
led mike24-Sep-07 4:57 
AnswerRe: Reading and writing to a named pipe C, C++, C# Pin
KarstenK26-Sep-07 4:06
mveKarstenK26-Sep-07 4:06 
QuestionSomething to reflect upon... Pin
Sandeep Datta22-Sep-07 20:31
Sandeep Datta22-Sep-07 20:31 
AnswerRe: Something to reflect upon... Pin
George L. Jackson23-Sep-07 4:50
George L. Jackson23-Sep-07 4:50 
GeneralRe: Something to reflect upon... Pin
Sandeep Datta23-Sep-07 19:50
Sandeep Datta23-Sep-07 19:50 
GeneralRe: Something to reflect upon... Pin
George L. Jackson24-Sep-07 0:35
George L. Jackson24-Sep-07 0:35 
GeneralRe: Something to reflect upon... Pin
Sandeep Datta24-Sep-07 1:22
Sandeep Datta24-Sep-07 1:22 
QuestionC++/CLI OpenGL performance Pin
Xpnctoc22-Sep-07 4:03
Xpnctoc22-Sep-07 4:03 
AnswerRe: C++/CLI OpenGL performance Pin
Luc Pattyn22-Sep-07 5:40
sitebuilderLuc Pattyn22-Sep-07 5:40 
GeneralRe: C++/CLI OpenGL performance Pin
Xpnctoc22-Sep-07 10:34
Xpnctoc22-Sep-07 10:34 
AnswerRe: C++/CLI OpenGL performance Pin
Mark Salsbery22-Sep-07 8:32
Mark Salsbery22-Sep-07 8:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.