|
ok but how do i seperate the data seperated by spaces or tabs in the text file to different cells in the excell file?
|
|
|
|
|
If it is tab, text would automatically be divided into cells. If it is space, you can replace them with tabs.
|
|
|
|
|
how do i replace space with tab? how do i write in the code to insert tab in a line?
|
|
|
|
|
greetings. i have an issue with the following code. for some reason whenever it is executed it is consuming around 60% of the CPU. this is strange, and was wondering if you had any comments?
private void HomeTableLayoutPanel_MouseMove(object sender, MouseEventArgs e)
{
PictureBox HomeCurrentPicBox = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location));
TableLayoutPanelCellPosition HomeCurrentPosition = new TableLayoutPanelCellPosition(-1, -1);
if (HomeCurrentPicBox != null)
{
HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox);
gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeCurrentPosition.Column) + "," + HomeCurrentPosition.Row.ToString());
}
}
thank you for your time.
|
|
|
|
|
This is happening beause the method is being called 100s of times when moving the mouse in one "jesture" over a significant distance. Put a breakpoint on and you'll see what I mean, the method is called almost per pixel moved. Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
|
|
|
|
|
1. During adding every PictureBox, add an eventhandler for MouseEnter and Leave. This will remove the need for GetChildAtPoint.
similarly, find some other places where refactoring could help you avoid repetative control
|
|
|
|
|
i hear what you are saying but that means i have to do it 200 times! ie th number of pictureboxes im using.
im trying to code it short by using table methods.
|
|
|
|
|
My Dear,
you must have added these controls inside tablelayoutpanel through code only... right? during adding it, you can add an eventhandler. So, this will be done only once... Its easier than you assume.
Try it. As a practice, if you need to copypaste a code without a reason, you are doing it wrong.
Som
|
|
|
|
|
i get what you are saying now. had not thought of it like that.
make all the picturebox share only one method upon event? right?
|
|
|
|
|
Try it. As a practice, if you need to copypaste a code without a reason, you are doing it wrong.
thats the reason im looking into this! i thought i had to issue 100/200 separate picture box events. but i can make them share just the one!
thanks for bringing this to attention once again.
|
|
|
|
|
good we all need a piece of advice once in a while... does wonders 
|
|
|
|
|
Hi,
I would like to draw onto a Windows form constantly, without freezing it.
I know it is possible, but how?
Thanks in advance.
|
|
|
|
|
Application.DoEvents() is probably what you're after. What sort of drawing are you doing continuously?Regards,
Rob Philpott.
|
|
|
|
|
I've thought about Application.DoEvents() but some say that it is not a safe solution. I think I can summarize what I am doing as creating random bitmaps until it is identical to another bitmap.
I know the concept is meaningless, but it is just a test which is leading to familiarizing myself with the idea of drawing onto Windows forms. 
|
|
|
|
|
Create timer and every tick event is fired call Invalidate() method
|
|
|
|
|
I've tried it but the form is still freezing and I've no control over it.
Here is the code I have in my OnPaint method.
protected override void OnPaint(PaintEventArgs e)
{
if (session == 0)
{
Graphics dc = e.Graphics;
Pen CyanPen = new Pen(Color.Cyan, 1);
Pen MagentaPen = new Pen(Color.Magenta, 1);
Pen YellowPen = new Pen(Color.Yellow, 1);
Pen BlackPen = new Pen(Color.Black, 1);
Random rnd = new Random();
int buff = 0;
for (int y = 0; y < 300; y++)
{
for (int x = 0; x < 300; x++)
{
buff = rnd.Next(0, 4);
if (buff == 0)
dc.DrawRectangle(CyanPen, x, y, 1, 1);
if (buff == 1)
dc.DrawRectangle(MagentaPen, x, y, 1, 1);
if (buff == 2)
dc.DrawRectangle(YellowPen, x, y, 1, 1);
if (buff == 3)
dc.DrawRectangle(BlackPen, x, y, 1, 1);
}
}
session++;
}
}
|
|
|
|
|
That's a lot of drawing 300 by 300 => 90000 rectagles in one session
Try putting a a this.Invalidate inside the first for and out of the second/inner for.
|
|
|
|
|
I tried your advise and still, I can't do anything on the form until the drawing is over.
|
|
|
|
|
I just realized that my first reply or message is a total ...
My bad.
All of the drawing is inside the OnPaint()!!!!
Use the fors outside the OnPaint() or better said call the paint or invalidate method
FROM the fors.
|
|
|
|
|
I see. But there is some thing that I don't understand. If I use OnPaint method, only for the painting process while randomizing in another method; how am I going to transfer my variables like color and position to the OnPaint method? I can use global variables but is it a good solution? There should be an easier and neater solution.
|
|
|
|
|
Yep. Create a method that draws.
Something like:
private void Draw(params here){
Grphics g = this.CreateGraphics();
}
And inside a for:
for(..){
Draw(params here);
this.Invalidate();
}
|
|
|
|
|
SimpleData wrote: use global variables
use class members to do so, and make sure your Paint handler executes fast.
I suggest you read this[^] little article of mine.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
modified on Friday, February 26, 2010 12:58 PM
|
|
|
|
|
Of course it keep freezing. In orther to respond, you need to make sure it only redraws once. And use timer.Tick event and forcfully call OnPaint by calling Invalidate(). Do not call OnPaint() directly. Invalidate works like a message pump (Or at least i think so). If it is called 3 times and redraw hasn't occourt, it will only redraw once, and clear quee.
other option is to put onto another thread. But i do not recomend. I would recomend a timer.
ps: Make sure to call dispose on a PEN, to clear unmanaged resources.
I would recomend you use only this code inside OnPaint. And make another Thread like a timer to Invalidate(), or OnPaint (Forcfully) as long as it doesn't call too frequent.
if (buff == 0)
dc.DrawRectangle(CyanPen, x, y, 1, 1);
if (buff == 1)
dc.DrawRectangle(MagentaPen, x, y, 1, 1);
if (buff == 2)
dc.DrawRectangle(YellowPen, x, y, 1, 1);
if (buff == 3)
dc.DrawRectangle(BlackPen, x, y, 1, 1);
|
|
|
|
|
This is my current code and I still have the freezing issue but I think we are getting there.
private void SetPixel(Point xy, Color clr)
{
Graphics dc = this.CreateGraphics();
Pen _pen = new Pen(clr, 1);
dc.DrawRectangle(_pen, new Rectangle( xy, new Size(1,1) ) );
_pen.Dispose(); dc.Dispose();
}
private void button1_Click_1(object sender, EventArgs e)
{
Random rnd = new Random();
int buff = 0;
for (int y = 0; y < 300; y++)
{
this.Invalidate();
for (int x = 0; x < 300; x++)
{
this.Invalidate();
buff = rnd.Next(0, 4);
if (buff == 0)
SetPixel(new Point(x,y),Color.Cyan);
else if (buff == 1)
SetPixel(new Point(x,y),Color.Magenta);
else if (buff == 2)
SetPixel(new Point(x,y),Color.Yellow);
else if (buff == 3)
SetPixel(new Point(x,y),Color.Black);
}
}
}
|
|
|
|
|
i would suggest what you have in button method you move to other thread. and it is incorect usage. you must let all drawing into OnPaint for perforamce. Invalidate prepares a message into a quee, when message pump has avaible slot, it will call OnPaint. Your Invalidate() is meanigless.
|
|
|
|
|