|
Hi,
there are many ways to achieve this.
Putting everything on one form and modify the Visible properties is NOT good.
And I would not put all the forms on a master form either.
Creating separate forms once, and showing/hiding them is one way.
This means you do not Close() any form, instead you Hide() it until you wamt to
Show() it again.
Creating separate forms once or more is also OK: when moving backwards in
the course, simply create a new instance of the Form and Show() it; when you dont
want to see it anymore, Close() it.
Hope this helps.
|
|
|
|
|
Hi Luc,
Thanks! That helps alot. Although, now I have another question (based on your suggestions). First, there should only ever be one instance of each form.
So if I have a button on form1 (btnNext) that opens form2, how do I go from form2 back to form1?
I can figure going forward:
form2 myForm2 = new form2();
myForm2.show(); //show form 2
this.hide(); //hide form1
But going back, how do I reference the form1 that's hidden in the form2 code? Is it as simple as:
myForm1.show();
this.close();
I would think that myForm1 would not be in the scope of the form2 class. Thanks again!
~~~~~~~~~~~~
Over-worked, under-paid, glorified "secretary"
|
|
|
|
|
Skcheng wrote: myForm1.show();
this.close();
Almost; it is:
myForm1.Show();
this.Hide();
Dont Close() forms you still want to be available for possible later use;
use Hide() instead.
|
|
|
|
|
Thanks again! Can't wait to get home to try this out.
~~~~~~~~~~~~
Over-worked, under-paid, glorified "secretary"
|
|
|
|
|
|
how do you attach a serial command to a button in c#?
i have a lutron rs232 controller for my lights, and i want to know how you attach an on/off command to it.
this is what i have
private void button1_Click(object sender, EventArgs e)
{
SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
port.Open();
port.Write("SDL,1,0") //just an example, "Set Dimmer Level, zone 1, 0 for off"
port.Close();
}
now the (SDL,1,0) i've put a "/r/n" as well, but i get no response.
i read that serial article for c#, but i'm confused to how you would use it. can someone n00b it up for me?
-- modified at 13:32 Tuesday 19th June, 2007
|
|
|
|
|
|
Hi,
Please see the function below.
When this function is called, it successfully finds the accurate value and assigns it to intFinalBaseIndexID i.e. return intFinalBaseIndexID; .
after the line i.e. return intFinalBaseIndexID; I am not sure why the function FinalBaseIndexID(dsCurves, intBaseIndexID, intBaseParentIndexID);//find the next Base... is called again? and so the function FinalBaseIndexID returns 0
Thanks
static int FinalBaseIndexID(DataSet dsCurves, int intIndexID, int intParentIndexID)
{
int intFinalBaseIndexID = 0;
//find the Base Index...
for (int intCurve = 0; intCurve < dsCurves.Tables.Count; intCurve++)
{
int intBaseIndexID = int.Parse(dsCurves.Tables[intCurve].Rows[0]["IndexID"].ToString());
int intBaseParentIndexID = int.Parse(dsCurves.Tables[intCurve].Rows[0]["ParentIndexID"].ToString());
if (intBaseIndexID == intParentIndexID)
{ //Base...
if (intBaseParentIndexID > 0)
{
FinalBaseIndexID(dsCurves, intBaseIndexID, intBaseParentIndexID);//find the next Base...
}
else
{
//Final Base...
intFinalBaseIndexID = intBaseIndexID;
}
}
if (intFinalBaseIndexID > 0)
{
break;
}
}
return intFinalBaseIndexID;
}
|
|
|
|
|
when you make the recursive call
FinalBaseIndexID(dsCurves, intBaseIndexID, intBaseParentIndexID);
you aren't storing the return value anywhere. Should it be
intFinalBaseIndexID = FinalBaseIndexID(dsCurves, intBaseIndexID, intBaseParentIndexID);
?
|
|
|
|
|
Is there an intrinsic way I can have a collection that has a separate dictionary key and a sort key? E.g. I want to store a collection of phone numbers, keyed by a TelNumberId int field, but sorted by a TelNumber string field.
|
|
|
|
|
If your dealing with classes (as aposed to structs) then I'd probably go for having 2 collections, one dictionary to act as the index and one List sorted in the order you want.
Each of these collections will only store the reference to the object so it's not like you'll be duplicating data.
|
|
|
|
|
Hi below is the code for conversion to grey scale image.
But i am getting exception at first line of the GrayScale function that
Object reference not set to an instance of an object.
I am using VS2005.
Any help would be appreciated....
Thanks
<br />
<br />
private Bitmap b;<br />
<br />
private void GrayScaleMenuItem_Click(object sender, System.EventArgs e)<br />
{<br />
if(GrayScale(b))<br />
this.Invalidate();<br />
}<br />
<br />
<br />
public static bool GrayScale(Bitmap b)<br />
{<br />
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);<br />
<br />
int stride = bmData.Stride;<br />
System.IntPtr Scan0 = bmData.Scan0;<br />
<br />
unsafe<br />
{<br />
byte * p = (byte *)(void *)Scan0;<br />
<br />
int nOffset = stride - b.Width*3;<br />
<br />
byte red, green, blue;<br />
<br />
for(int y=0;y<b.Height;++y)<br />
{<br />
for(int x=0; x < b.Width; ++x )<br />
{<br />
blue = p[0];<br />
green = p[1];<br />
red = p[2];<br />
<br />
p[0] = p[1] = p[2] = (byte)(.299 * red + .587 * green + .114 * blue);<br />
<br />
p += 3;<br />
}<br />
p += nOffset;<br />
}<br />
}<br />
<br />
b.UnlockBits(bmData);<br />
<br />
return true;<br />
}
|
|
|
|
|
It seems that variable b is not initialized and its value is null
|
|
|
|
|
oh yeh...now i initialized it as
b = new Bitmap(2,2);
exception is solved but after i press button for grey scale..Nothing is happening.
Cursor is going to Invalidate. And no change in pic
Thanks
|
|
|
|
|
You have modified a bitmap in memory; how would that affect your display ?
To get a visual change you must:
- make sure the bitmap is shown somewhere in a Form or Control (e.g. it gets drawn
in a Panel);
- tell that Form/Control that it needs to redraw because its content has changed;
you do this by calling Control.Invalidate()
Now a 2*2 bitmap probably is hardly visible at all, so dont expect a
huge change in your display when you grayscale it !
|
|
|
|
|
Sorry but its not too clear to me....
How to show bitmap on form or control ???
How to tell the form that it needs to redraw...?
And then how can i get a good change in display if 2*2 wont make much differnce..?
Thanks
|
|
|
|
|
Software_Specialist wrote: How to show bitmap on form or control ???
by drawing it in the form/control's paint handler, using Graphics.DrawImage
Software_Specialist wrote: How to tell the form that it needs to redraw...?
see previous message
Software_Specialist wrote: And then how can i get a good change in display if 2*2 wont make much differnce..?
try a larger bitmap !
|
|
|
|
|
ok now i know what you mean...
you mean to write as shown below:::
<br />
protected override void OnPaint (PaintEventArgs e)<br />
{<br />
Graphics g = e.Graphics;<br />
<br />
g.DrawImage(m_Bitmap, new Rectangle(this.AutoScrollPosition.X, this.AutoScrollPosition.Y, (int)(m_Bitmap.Width*Zoom), (int)(m_Bitmap.Height * Zoom)));<br />
}<br />
And for this i have to remove the picture box from the form. But i am writing an application for image viewer. i.e. Slide show and for that i need few of the image processing stuff..So for that i guess i need to have picture box ..
Moreover its not working out for me. I have just tried to load the picture with a following code
<br />
private void File_Load(object sender, System.EventArgs e)<br />
{<br />
OpenFileDialog openFileDialog = new OpenFileDialog();<br />
<br />
openFileDialog.InitialDirectory = "c:\\" ;<br />
openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*.bmp/*.jpg)|*.bmp/*.jpg";<br />
openFileDialog.FilterIndex = 2 ;<br />
openFileDialog.RestoreDirectory = true ;<br />
<br />
if(DialogResult.OK == openFileDialog.ShowDialog())<br />
{<br />
m_Bitmap = (Bitmap)Bitmap.FromFile(openFileDialog.FileName, false);<br />
this.AutoScroll = true;<br />
this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));<br />
this.Invalidate();<br />
}<br />
}<br />
But it gives me a blinkin form..I mean photo is not stable. It comes and go off every msec...
Well i am referring http://www.codeproject.com/cs/media/csharpgraphicfilters11.asp
Any solution...???
Thanks
|
|
|
|
|
I never felt the need for a PictureBox, I prefer drawing on a Panel, so I know
exactly what is being drawn, how it gets scaled, etc.
I never used AutoScroll but I think your AutoScrollMinSize is wrong;
I suggest you try it once without that line...
|
|
|
|
|
well no its not working without that aswell...
I am referring to CG article and in his demo its workin fine.
And yeah i am not drawing it on panel...Its just a form and that override command.
And what about slide show ? Would i be able to get that functionality if i draw on form without using picturbox.. ?
Thanks
|
|
|
|
|
a picturebox is like a panel that knows how to load an image file,
and how to draw an image; you already did both.
To make a slide show you just need to load and display consecutive images,
triggered by something (maybe a button click, maybe a timer tick).
BTW: you must Dispose of your OpenFileDialog !
|
|
|
|
|
yo removed OpenFileDialog and now using direct instance of it..
But no work as yet..Ok ill try to figure it out ....
Actually i am new to IP. But thanks for pointing me out these basic things..and so to basically we dont need any panel or picturebox dropped over form..We can just draw it once...oks
ill try to figure out the prob nw...
cheers
|
|
|
|
|
What I meant is you must call openFileDialog.Dispose() when you no longer need
that instance of OpenFileDialog, otherwise you may get a memory leak.
|
|
|
|
|
yeh got the solution to it...well doublebuffer property was set to false...
So i setted it to true and is working now...
ta
|
|
|
|
|