Click here to Skip to main content
15,911,896 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: adding a panel to a form. [modified] Pin
bimbambumbum22-Sep-10 14:42
bimbambumbum22-Sep-10 14:42 
AnswerRe: adding a panel to a form. Pin
Luc Pattyn22-Sep-10 15:28
sitebuilderLuc Pattyn22-Sep-10 15:28 
GeneralRe: adding a panel to a form. Pin
bimbambumbum22-Sep-10 17:04
bimbambumbum22-Sep-10 17:04 
AnswerRe: adding a panel to a form. Pin
Luc Pattyn22-Sep-10 17:13
sitebuilderLuc Pattyn22-Sep-10 17:13 
GeneralRe: adding a panel to a form. Pin
bimbambumbum25-Sep-10 4:46
bimbambumbum25-Sep-10 4:46 
GeneralRe: adding a panel to a form. Pin
Luc Pattyn25-Sep-10 5:21
sitebuilderLuc Pattyn25-Sep-10 5:21 
GeneralRe: adding a panel to a form. [modified] Pin
bimbambumbum25-Sep-10 5:31
bimbambumbum25-Sep-10 5:31 
GeneralRe: adding a panel to a form. Pin
Luc Pattyn25-Sep-10 6:08
sitebuilderLuc Pattyn25-Sep-10 6:08 
OK, here are the most relevant chunks of my experiment, all is in the MainForm class; I'll probably crank out another little article by the end of next week:

// some data members
private Bitmap bmPlot;
private int dataCount;
private BackgroundWorker bgw;
private bool running;
private int oldy=-1;
private Graphics bmg;

// the paint handler
private void plotter(object sender, PaintEventArgs e) {
	if (bmPlot!=null) {
		Graphics g=e.Graphics;
		int w=plot.Width;
		int h=plot.Height;
		int x=dataCount%w;
		g.DrawImage(bmPlot, new Rectangle(0, 0, w-x, h), new Rectangle(x, 0, w-x, h), GraphicsUnit.Pixel);
		g.DrawImage(bmPlot, new Rectangle(w-x, 0, x, h), new Rectangle(0, 0, x, h), GraphicsUnit.Pixel);
	}
}

// the button that causes things to start plotting
private void btnStart_Click(object sender, EventArgs e) {
	log("btnStart_Click");
	btnStop.Enabled=true;
	btnStart.Enabled=false;
	running=true;
	dataCount=0;
	oldy=-1;
	int w=plot.Width;
	int h=plot.Height;
	bmPlot=new Bitmap(w, h);
	bmg=Graphics.FromImage(bmPlot);
	bmg.FillRectangle(Brushes.Yellow, 0, 0, w, h);
	plot.Refresh();
	bgw=new BackgroundWorker();
	bgw.DoWork+=worker;
	bgw.ProgressChanged+=reporter;
	bgw.WorkerReportsProgress=true;
	log("starting bgw");
	bgw.RunWorkerAsync();
}


and all the code that belongs to the BGW, which takes care of modifying the bitmap content (one column at a time):
private void worker(object sender, object e) {
	while (running) {
		AddNewData();
		bgw.ReportProgress(0);
		Thread.Sleep(30);
	}
}

private void reporter(object sender, object e) {
	log("reporter");
	plot.Invalidate();
}

private void AddNewData() {
	int w=plot.Width;
	int h=plot.Height;
	int x=dataCount%plot.Width;
	bmg.DrawLine(Pens.Yellow, x, 0, x, h);
	int y=(int)(h*(0.5+0.45*Math.Sin(dataCount*0.07)));
	if (oldy<0) oldy=y;
	bmg.DrawLine(Pens.Black, x, oldy, x, y);
	oldy=y;
	dataCount++;
}


Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.


GeneralRe: adding a panel to a form. [modified] Pin
bimbambumbum25-Sep-10 11:20
bimbambumbum25-Sep-10 11:20 
GeneralRe: adding a panel to a form. Pin
Luc Pattyn25-Sep-10 12:02
sitebuilderLuc Pattyn25-Sep-10 12:02 
QuestionsqlDataAdapter doest not refresh the query Pin
akosidandan22-Sep-10 5:20
akosidandan22-Sep-10 5:20 
AnswerRe: sqlDataAdapter doest not refresh the query Pin
Not Active22-Sep-10 7:42
mentorNot Active22-Sep-10 7:42 
GeneralRe: sqlDataAdapter doest not refresh the query Pin
akosidandan22-Sep-10 22:40
akosidandan22-Sep-10 22:40 
GeneralRe: sqlDataAdapter doest not refresh the query Pin
Not Active23-Sep-10 1:08
mentorNot Active23-Sep-10 1:08 
QuestionHow to Show Specific Records in listview Pin
akosidandan22-Sep-10 1:38
akosidandan22-Sep-10 1:38 
AnswerRe: How to Show Specific Records in listview Pin
Luc Pattyn22-Sep-10 2:23
sitebuilderLuc Pattyn22-Sep-10 2:23 
GeneralRe: How to Show Specific Records in listview Pin
akosidandan22-Sep-10 2:29
akosidandan22-Sep-10 2:29 
GeneralRe: How to Show Specific Records in listview Pin
Luc Pattyn22-Sep-10 2:47
sitebuilderLuc Pattyn22-Sep-10 2:47 
QuestionFile recovery Pin
hammerstein0522-Sep-10 0:57
hammerstein0522-Sep-10 0:57 
AnswerRe: File recovery Pin
Pete O'Hanlon22-Sep-10 1:37
mvePete O'Hanlon22-Sep-10 1:37 
GeneralMessage Removed Pin
22-Sep-10 4:23
molesworth22-Sep-10 4:23 
GeneralRe: File recovery Pin
Pete O'Hanlon22-Sep-10 4:35
mvePete O'Hanlon22-Sep-10 4:35 
GeneralRe: File recovery [modified] Pin
molesworth22-Sep-10 4:38
molesworth22-Sep-10 4:38 
AnswerRe: File recovery Pin
molesworth22-Sep-10 4:48
molesworth22-Sep-10 4:48 
GeneralRe: File recovery Pin
hammerstein0522-Sep-10 5:39
hammerstein0522-Sep-10 5:39 

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.