|
Hello...
You can use public variable to which you can pass value...Like
suppose if you have two forms Form1 n Form2. Now you want to pass value from Form1 to Form2.....First make a public variable in Form2 then in Form1 use the following code.
Form2 obj = new Form2();
obj.yourpublicvariable = "some value"; // assign value to public var of form2
// ur code
................................................
The other way could be that you can pass the value to Form2 via Constructor.like
Form2 obj = new Form2("Some Value");
//For this you must write your own constructor in Form2 accepting the value u r passing.
Hope this helps
regards
mubashir
|
|
|
|
|
_mubashir wrote: You can use public variable to which you can pass value
Ugghh! That is a bad idea and here's why[^]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Thanx pal for correcting me...
regards
mubashir
|
|
|
|
|
You can read this article on passing values between forms[^]
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
Anybody know how to play a video file in the user Default player using C#?
Looking forward to a favourable reply.
Rgds,
Sam J
|
|
|
|
|
Hi,
System.Diagnostics.Process.Start("C:\\Movies\\MyMovie.mpg");
|
|
|
|
|
Hi Robert,
Great work. It works.
Thank you very much...
Rgds,
Sam J
|
|
|
|
|
Hello all...
I am testing a web application using C#, i am creating an automated test and i managed to click images, buttons, and links on the web page using MSHTML library, but i have two questions:
1. How can i move the mouse pointer to the button or the image or anything i click?
2. How can i select from a dropdown menu (combobox)?
Any help is really appreciated
Thanks in advance
Waleed
Thanks
|
|
|
|
|
Hi,
I've developed a custom struct and its editor (custom datetime).
but the problem is that the VS designer decides to serialize it as a resource for the window form which has used my struct (because the struct is ISerializable, IXmlSerializable, IConvertible and [Serializable])
But whenever I recompile my library, the windows.forms designer generates an exception about serialization...
the exception title is:
"Cannot convert type MyStruct to type MyStruct" (note that types are the same )
I thinks it is because of BinaryFormatter (or CodeDomSerializer I think) which could not deserialize a struct with different assembly version.
Due to it is a struct not a class, I cannot use
System.ComponentModel.DesignerSerializerAttribute,
System.ComponentModel.DesignerSerializationVisibilityAttribute,
System.Configuration.SettingsSerializeAsAttribute
which might solve the problem.
The other solution is that somehow I generate the code
"myControl.myProperty = new MyStruct("str");"
instead of
"myControl.myProperty = ((MyStruct) resources.GetObject("myProperty");".
I know it is pussible through UITypeEditor, but I don't know how
I tried to implement a special TypeConverter for it too, but the problem exists yet.
Please Help me
Best Regards,
Kamran Fallah
-- modified at 23:01 Sunday 30th April, 2006
|
|
|
|
|
Hi,
here is some code from one of my projects (hopefully becoming an article soon) where I had the same problem. ProgressStep is in this case the class the designer didn't hadnle nicely:
[TypeConverter(typeof(ProgressStepConverter))]
public class ProgressStep
{
public ProgressStep(Image image, string name, string description)
{
}
}
public class ProgressStepConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destType)
{
if (destType == typeof(InstanceDescriptor))
return true;
return base.CanConvertTo(context, destType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo info,
object value, Type destType )
{
if (destType == typeof(InstanceDescriptor))
{
ProgressStep step = (ProgressStep)value;
Type[] ctorTypes = new Type[] { typeof(Image), typeof(string), typeof(string) };
object[] ctorParams = new object[] { step.Image, step.Name, step.Description };
return new InstanceDescriptor(typeof(ProgressStep).GetConstructor(ctorTypes),
ctorParams, true);
}
return base.ConvertTo(context, info, value, destType);
}
}
|
|
|
|
|
I can't understand what you did...
I've logged the function calls to TypeConverter with message box, but it usually requests for converting to/from type string, not ITypeDescriptor...
The second problem is that I've checked the application.settings file and now I'm sure it serialize my struct to correct customized "xml" (not binary).
I guess the problem is in the .settings file, the VS 2005 stores the version of referenced library.
Please note that I'm converting a "struct" no a "class". The differences are too much!
By the way, can you explain how your code works?
Thanks
|
|
|
|
|
The code should generally make the designer creating entries in InitializeComponent which look like:
bla.ProgressStep = new ExtendedPictureBoxLib.ProgressStep(
null, "StepName", "Processing step \'{0}\' ({1}/{2})...")
I think the designer tries several conversions and will decide on what to do depending on which transformation succeeds. So what ConvertTo does in general is telling the designer which parameters go into the constructor. It is important that there is a constructor which gets all parameters of your class (that's why I also posted it).
You could look at this[^] article to get a better understanding.
|
|
|
|
|
Thank you!
The problem was my ConvertTo method returned true to string, MyStruct types. So The designer didn't ask me for conversion to "InstanceDescriptor" type.
|
|
|
|
|
Thank you!
The problem was my ConvertTo method returned true to string, MyStruct types. So The designer didn't ask me for conversion to "InstanceDescriptor" type. )
|
|
|
|
|
Thank you!
The problem was my ConvertTo method returned true to string, MyStruct types. So The designer didn't ask me for conversion to "InstanceDescriptor" type.
|
|
|
|
|
I have an image and I'd like to automatically save a particular section of the image that's I've predefined. E.G. 100 pixels right, 200 pixels, 100 pixels width, 200 pixels height.
I'd like to be able to open a tiff file and then auto create a tiff of the particular area of the image.
|
|
|
|
|
Hi,
something like the following should work:
//given: newWidth, newHeight, offsetRight, offsetTop
Bitmap originalBitmap = new Bitmap("C:\\MyTiff.tif");
Bitmap newBitmap = new Bitmap(newWidth, newHeight);
using (Graphics g = Graphics.FromImage(newBitmap) {
Rectangle destRect = new Rectangle(0, 0, newWidth, newHeight);
Rectangle sourceRct = new Rectangle(offsetRight, offsetTop, newWidth, newHeight);
g.DrawImage(originalBitmap, destRect, sourceRect);
}
newBitmap.Save("C:\\MyNewTiff.tif");
Coded from memory without testing so there might be little mistakes in it . But the idea should be clear I hope.
|
|
|
|
|
Thanks. That works great.
|
|
|
|
|
I have a list box control on a web form that displays some data from a database. Each time a different item is selected in this list box I want to display some data in another list box, so I am handeling the SelectedIndexChanged event. My problem is that the event doesn't seem to be firing. This is what I am using:
protected void GroupList_SelectedIndexChanged(object sender, EventArgs e)
{
int index = GroupList.SelectedIndex;
DataRow[] rows = dSet.Tables["Mounts"].Select("Group_Number =" + GroupList.Items[index].Text);
foreach (ListItem item in MountList.Items)
{
MountList.Items.Remove(item);
}
foreach (DataRow row in rows)
{
MountList.Items.Add(row[0].ToString());
}
}
When I run this and select different items in the list box, nothing happens. Any ideas why?
Thanks for any responses
|
|
|
|
|
Possible clauses.
- How you handle the initliazation.
- If its running it on the server this function.
- If this method isnt being added on the specific control.
|
|
|
|
|
What initialization is there to be done?
Sean
|
|
|
|
|
Well, more of the case of Web Forms how you need to check if your reloading those Listboxes again, and if so that whenever you reload the page again, it might reload those items again and reset whatever changes you want in the first place.
Another issue becomes if its stateless or not (meaning does it retain the data when you press on buttons, that go back to the server to process things and spit back out the result on the WebForm that you asked for).
Web Forms are really difficult to determine where your problem is. You need to check how the flow of the web form works, but from hazarding a guess of why nothing is happening is most possibly that you are resetting those listboxes to that nothing is happening.
But this is just guessing, it'd be better with a full code rather than a specific method, but thats your call.
Kuira
|
|
|
|
|
Hi,
How do u stop a button that has been pressed from firing again when the enter/return key is pressed?
(and the answer does NOT seem to be: Put "none" in the form1 "AcceptButton" property ... cuz once the button has been pressed with the mouse, it seems to automatically become the default button that is fired when the enter key is pressed the next time)
Thanks for your time.
IceWater42
|
|
|
|
|
The main problem you encounter is that while focused the control processes key messages and hadles them (ie - you press space or enter the button is pressed).
In order to bypass this you have to inherit the Button class and override it's ProcessCmdKey method. This will allow you to skip some keys you don't want to be processed.
Here's an example :
namespace MyCustomControls
{
public class SpecialButton : Button
{
ArrayList skipTheseKeys;
public SpecialButton()
{
skipTheseKeys = new ArrayList();
skipTheseKeys.Add(Keys.Space);
skipTheseKeys.Add(Keys.Tab);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (skipTheseKeys.Contains(keyData))
return true;
else
return base.ProcessCmdKey(ref msg, keyData);
}
}
}
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
AHA .. i get the idea ... thank you
I added the code in front of my existing namespace but i do not know how to get the compiler to cause the override to be activated. I put a break on the IF statement but it never gets executed, so the problem still exists
|
|
|
|