|
Your question is not clear. How can you put class instances into form ? Are you developing any componenent that can be sited in the designer ? If yes, derive your class from Component class.
netJP12L wrote: ClassA intializes ClassB and ClassC
Something like this ?
class ClassA
{
private ClassB instanceB;
public ClassB InstanceB
{
get { return instanceB; }
set { instanceB = value; }
}
private ClassC instanceC;
public ClassC InstanceC
{
get { return instanceC; }
set { instanceC = value; }
}
public ClassA()
{
instanceB = new ClassB();
instanceC = new ClassC();
}
}
class ClassB
{
}
class ClassC
{
}
|
|
|
|
|
Thanks for answering but I am trying to develop controls classes. What i want to achieve is that lets say I have an objecX control, and ObjectY control if i delete objectX control so the classY control should be removed if i delete objectY the objectX control should be removed as well.
These two control are depeneded on each other in terms of they both resides or none of them. Each one of them have different behavior and knows how to draw themselves(objectX control and objectY control).
I could have look for either of these two objects on a Form and if one is going to removed then the other one should be removed. But keep in mind is that there could be multiple instances of these 2 control, I think i could call them a composite objects. That's where i am getting struck and not sure how to solve this.
please help thanks
|
|
|
|
|
Sadly, there isn't any concept of deletion in c#. But, since you are using form controls, you could remove the each control from the form.
But here, since you can have many controls of the same type on the form, and one control is independent of the other, you do not have a proper object communication mechanism in place. A possible solution is not to use your custom classes directly, but to have ObjectManager class that would provide functionality to add, remove controls from the parent control(Form). You can then implement the Remove method to do whatever functionality you need since now everything would lie in the hands of the ObjectManager.
|
|
|
|
|
Exactly, that's what i am realizing too. I would appreciate it if you can provide me a demo examples.
|
|
|
|
|
Hi all.
Always I was seeing object sender in parameters of event's method.
What is this and How we can access to the content of it ?
Sample :
void rectangle_MouseDown(object sender, MouseButtonEventArgs e)
{
}
Thanks in advance.
Freshman
|
|
|
|
|
Hi,
object sender is the object (usually a Control) that fired the event.
You can use it by casting it to the appropriate type.
Example: when several Buttons share the same Click handler, do
Button btn=(Button)sender; and now you can use btn.Name, btn.Text, btn.Tag or
whatever you choose to identify which of those Buttons fired the event.
|
|
|
|
|
Nice
Thanks Luc Pattyn.
Freshman
|
|
|
|
|
To extend Luc's answer slightly - the pattern when raising an event is normally to use something like this:
protected virtual void OnMyEvent()
{
if (MyEvent != null)
MyEvent(this , new EventArgs());
}
|
|
|
|
|
I stand slightly extended.
|
|
|
|
|
Pete O'Hanlon wrote: if (MyEvent != null)
MyEvent(this /* This populates the sender object */, new EventArgs());
What's MyEvent. Is it object or method name.
Freshman
|
|
|
|
|
MyEvent was just an example for a name of an event. It could be any event that you want to use.
|
|
|
|
|
Pete O'Hanlon wrote: new EventArgs());
EventArgs.Empty I say!
|
|
|
|
|
leppie wrote: EventArgs.Empty I say!
MyEvent overloaded him. What do you think this would do?
|
|
|
|
|
Pete O'Hanlon wrote: MyEvent overloaded him. What do you think this would do?
Probably what you intended it to do?
EventArgs.Empty is just a an empty instance which is equivalent to new EventArgs().
|
|
|
|
|
Hello.
I have this wierd problem when im writing to a text file with data from a array
I have this method:
private void writeData()
{
StreamWriter writeData = new StreamWriter(saveMonsterSetBase.FileName, false);
for (int x = 0; x < MonsterSetBaseDataArray.Count; x++)
{
writeData.WriteLine(MonsterSetBaseDataArray[x]);
}
writeData.Close();
}
Which is trigged here:
saveMonsterSetBase.ShowDialog();
if (saveMonsterSetBase.FileName != "")
{
writeData();
}
It works fine and opens my saveFileDialog
But after I save it I get a "file not found" on some other method I use
This is some of the method:
StreamReader findMonsterStream = new StreamReader(@XMLmonsterLocation);
I get the error monster.txt (XMLmonsterLocation) is not found
It looks like the writedata changes the local path because it says
File not found in the path where I saved the file
Example:
The application and monster.txt (XMLmonsterLocation) is saved in D:\
I then use the saveFileDialog (I save a file to for example C:\) and when I access my method where I use the XMLmonsterLocation it says file not found in C:\
So I dont know why
Hope you understand
The StreamReader reads from a xml file that looks like this:
<config>
<monsterlocation>monster.txt</monsterlocation>
<monstersetbaselocation>MonsterSetBase.txt</monstersetbaselocation>
<monsterimagelocation>mobs\</monsterimagelocation>
<mapimagelocation>maps\</mapimagelocation>
<mapinfolocation>maps\maps.txt</mapinfolocation>
</config>
|
|
|
|
|
Hi,
Windows keeps a "current directory" for every process.
There are several ways to modify the curdir, browsing with an Open/SaveFileDialog is one of them;
check this: the second time you open such a dialog, it shows the folder you saw last.
You can prevent this from persisting by setting FileDialog.RestoreDirectory true.
In general you should not rely on the curdir, so basically your mistake is that the
StreamReader uses a relative path. If you want it to always read files from your EXE's folder
write code to enforce that; have a look at Application.StartUpPath
|
|
|
|
|
Hi
I know how to convert schema into class using XSDObjGenVSAddin tool. But, how can I convert C# class into xml schema? Is there any tool available for this?
Please advise. Thanks
Pankaj
modified on Wednesday, July 2, 2008 3:38 PM
|
|
|
|
|
pankazmittal wrote: But, how can I convert C# class into xml schema?
Very carefully.
led mike
|
|
|
|
|
|
Purpose : Read the contents of a CSV file and write it to a database in a varbinary field. Once written, read the contents and write it to a CSV file.
Issue: I am able to serialize and write the contents to the database.I am having issues when I deserilaize the file contents. I am getting an error "Trying to deserilaize an empty stream".
Please find below the code used to serialize and deserialize
private object SerializeFileContent(string filePath)
{
if (filePath != null)
{
//write the fielcontents to a byte array
FileStream st = new FileStream(filePath, FileMode.Open);
byte[] buffer = new byte[st.Length];
st.Read(buffer, 0, (int)st.Length);
st.Close();
//serilaize the bytearray and write it to a memory stream
MemoryStream serializedStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(serializedStream,buffer);
//Read Memory Stream into Byte Array
int streamLength = Convert.ToInt32(serializedStream.Length);
byte[] serilaizedArray = new byte[streamLength];
serializedStream.Write(serilaizedArray,0,streamLength);
return serilaizedArray;
}
else
return null;
} public void DeserializeFileContent(string FileId,string filePath)
{
//read the file contents and write it to a stream
SqlConnection CCSProductCatalogArchiveConn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["CatalogArchiveConnectionString"]);
SqlParameter sqlFileId = new SqlParameter("@FileId", SqlDbType.NVarChar,100);
sqlFileId .Value = FileId;
//Populates parameter array to be passed into DataUtil.ExecuteNonQuery
SqlParameter[] sqlParams = new SqlParameter[1];
sqlParams[0] = sqlFileId;
DataSet fileContents = DataUtil.LoadDataSet(CCSProductCatalogArchiveConn, "GetFileContents", true, sqlParams);
MemoryStream mstream = new MemoryStream();
StreamWriter writer = new StreamWriter((mstream);
writer.Write(fileContents);
mstream.Length
//Deserialize the contents
object o;
BinaryFormatter formatter = new BinaryFormatter();
o = (object) formatter.Deserialize(mstream);
}
Thanks
Hema
|
|
|
|
|
Member 3449442 wrote: MemoryStream mstream = new MemoryStream();
StreamWriter writer = new StreamWriter((mstream);
writer.Write(fileContents);
You need to reset the position to 0 after that
|
|
|
|
|
I am creating a ToolStrip that I have a DateTimePicker added on using the following code:
DateTimePicker FromDate = new DateTimePicker();
FromDate.Format = DateTimePickerFormat.Short;
MainToolStrip.Items.Add(new ToolStripControlHost(FromDate));
I am wanting to change the width of the DateTimePicker to be just large enough to fit the text needed. My thought was to measure the MaxDate value string using the font and that would be the width, like so:
Size dtps = TextRenderer.MeasureText(FromDate.MaxDate.ToShortDateString(), FromDate.Font);
FromDate.Size = dtps;
This works, except for one problem, it does not include the width for the drop down button on the DateTimePicker control, so it overlaps the text. I do not know how to get the width of the drop down button on the DateTimePicker, and my searches have been less than successful. Does anyone have a reference to where I can learn how to do this?
Also, is there any good references that go into some of this type of detail? Most of the books and websites I visit will teach you the basics of a control, like how to change the font, width, height, and common properties, but I would like to get a bit deeper with these items and really see what they can do. I think these books might be what I am looking for, but have not got them yet:
'GDI+ Custom Controls with Visual C# 2005' by Tiberiu Radu, Iulian Serban, Dragos Brezoi, Adam Ward
'Pro .NET 2.0 Windows Forms and Custom Controls in C#' by Matthew MacDonald
'Windows Forms 2.0 Programming' by Chris Sells, Michael Weinhardt
Anyone have any experience with these books, or maybe could recommend something similar?
Thanks for your time, in advance! =)
|
|
|
|
|
In regards to measuring your text, you could just add a constant value to the total width assuming the size of the button does not change.
Just because we can; does not mean we should.
|
|
|
|
|
hpjchobbes wrote: This works, except for one problem, it does not include the width for the drop down button on the DateTimePicker contro
I am having success using SystemInformation.VerticalScrollBarWidth for the dropdown button width in my experiments.
led mike
|
|
|
|
|
I am creating an IE toolbar and I need it to launch a javascript page when the toolbar button is clicked.
Below is the code that I am using and getting errors.
private void btnToolStrip_Click(object sender, EventArgs e)
{
// Launches the post window
Page.ClientScript.RegisterStartupScript(this.GetType(), "CustomButton", "<script language=JavaScript> window.open('http://hvkclncswsvr10.gign.kcl.mtec.mds.lmco.com/tachyon_proj/post/?item='" + content.document.location.href + "'&title='" + encodeURIComponent(document.title) + "','Tachyon Post','width=850,height=500,resizable=yes');</script>");
}
When i build this i get errors on the name Page, content, encodeURIComponent, and document. Is it possible to run the JS this way from a ToolStripButton clcik event or do I need to do it another way?
<div class="ForumMod">modified on Wednesday, July 2, 2008 11:48 AM</div>
|
|
|
|