|
|
Override the onDrawItem event:
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
{
// Your menu drawing code
}
and set the OwnerDraw property of the menu items to "True"
--Aditya
|
|
|
|
|
Thanks for your help but there is no OwnerDraw property to the main form ( no this.OwnerDraw )and no OnDrawItem() to override from......
What have I missed ?
Udi
|
|
|
|
|
Hi,
I have a MDI form with a Main Menu item.
when i click a menuitem(say Create Child) i want to show a different form as the child form for the MDI form.
The following is the code which i have in the click event of the menu item.
private void mnuitmCreateChild_Click(object sender, System.EventArgs e)
{
Child frmChild=new Child(); // create an istance of the child from
frmChild.MdiParent=this; // make the MDI form as the parnet for the created child form
frmChild.Show(); // show the child form
}
When i click the menu item for the first item an instance of the form is created and shown as the child form. That is what i want.
But, my problem is when i click the menuitem(Create Child) one more time keeping the child created previously, one more instance of the same child is being created and shown as a different window.
How can i make sure that only one child is active all the time?
Thanks in advance.
|
|
|
|
|
Subrahmanyam_K wrote:
But, my problem is when i click the menuitem(Create Child) one more time keeping the child created previously, one more instance of the same child is being created and shown as a different window.
So, what you want is to make sure that only one instance of a particular child can be created?
The simplest way, and the best way with regards to feedback to the user, is to disable the menu item that creates that child, after it's been created. When the child is closed, re-enable the menu item. That way, the user gets some feedback when going to the menu that the child has already been created. The "Windows" menu item should show a list of all the child forms, BTW.
Otherwise, you'll probably have to maintain a collection of child forms and test to see if the child has already been created, and if so, bring it to focus. But you'll still need to handle the child's close event so that it can remove itself from the application's collection.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Thanks a lot for your suggestions.
That's a very good idea which provides some information to the user that the form has already opened.
Thank you once again.
Subrahmanyam.
|
|
|
|
|
well it makes a new instance because you type "Child frmChild = new Child();"
instead you want the singleton approach:
just add static instance attribute and static getInstance method -
<br />
class Child : Form {<br />
<br />
static Child instance=null;<br />
<br />
static Child getInstance() {<br />
if (instance==null) instance=new Child();<br />
return instance;<br />
}<br />
...the rest of the child class...<br />
}<br />
<br />
private void mnuitmCreateChild_Click(object sender, System.EventArgs e)<br />
{<br />
Child frmChild= Child.getInstance(); <br />
frmChild.MdiParent=this;
frmChild.Show();
}<br />
this way only one chlid form will form, and you can access it from everywhere in you program by using "Child.getInstance();"
if the constructor needs params then this complicates things but is still doable.
good luck,
Iftah.
|
|
|
|
|
Thanks a lot for the piece of code.
Subrahmanyam.
|
|
|
|
|
This is what I usually do: (actual code from an app I'm working on right now)
foreach(Form form in MdiChildren)
{
if(form is AttendanceForm)
{
if(form.WindowState == FormWindowState.Minimized)
form.WindowState = FormWindowState.Normal;
form.Activate();
return;
}
}
AttendanceForm af = new AttendanceForm();
af.MdiParent = this;
af.Visible = true;
I hope it helps.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I would like to find out how do I authenticate a user against a database in SQL 2000?
I am using VS 2003.
Illegal Operation
WannaBe and GonnaBe Systems Developer
|
|
|
|
|
|
Hello,
I have created a C# application that calling the stored procudure in MS Access DB file.
Here's the sql for stored procedure called procs_BestMark:
"PARAMETERS startDate DateTime, endDate DateTime;
SELECT Max(Marks) AS Expr1
FROM Students
WHERE (((Students.ExamTime) Between [startDate] And [endDate]));"
Here's my code in C# to call the stored procedure after connected the MS Access DB successfully:
"
odbcnStudentStatus.Open();
odbCommand = new OleDbCommand("procs_BestMark", odbcnStudentStatus);
odbCommand.CommandType = CommandType.StoredProcedure ;
odbCommand.CommandText = "exec procs_BestMark ?, ?";
OleDbParameter paraSD = this.odbCommand.Parameters.Add("startDate",OleDbType.DBDate);
paraSD.Value = new DateTime(2000,1,1);
OleDbParameter paraED = this.odbCommand.Parameters.Add("endDate",OleDbType.DBDate);
paraED.Value = new DateTime(2006,1,1);
int max = (int)this.odbCommand.ExecuteScalar();
"
It throws an error: "oleDBException: Expected query name after EXECUTE."
What is that? I think I have assigned the name of the stored procedure successfully.
Please help!
Thanks
|
|
|
|
|
|
I'm a newbie to control design in C#.
I want to have a .Tag property on all controls or at least a ResourceID property. Can I just inheirit from the base control and extend a new property while keeping all functionality from the original control. Please don't tell me to just find it on the internet, but maybe a real simple example.
Thank you
Fear is the mind killer.
|
|
|
|
|
Wackatronic1 wrote:
I want to have a .Tag property on all controls
Erm, Tag is already a property of Control, so there's no need to derive from it. And, if you want to add a property that is available to all controls, you're MUCH better off implementing it using the IExtenderProvider interface, like the way the ToolTip class works. (And yes, for IExtenderProvider, I'm going to tell you to read the documentation )
The advantage with IExtenderProvider is that you can still use the controls in the designer, and the new property shows up when you drop your extender provider onto the form.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Hi,
I populate a CheckedListBox with a DataTable:
checkedListBox1.DataSource = myDT;
checkedListBox1.DisplayMember = "Name";
checkedListBox1.ValueMember = "ID";
I was wondering if it's possible to get the SelectedValue of every checked (or even selected) item with some sort of loop?
Ron
|
|
|
|
|
|
Hi Yulianto,
Thanks for the link (sorry, I'm a new programmer)...
I've been to that web page before and couldn't figure out from it
how to access the ValueMember data from it.
It only shows how to access the index or text of each item.
The checkedListBox1.CheckedItems object does not seem to include the ValueMember of each item.
thanks,
Ron
|
|
|
|
|
myNameIsRon wrote:
how to access the ValueMember data from it.
What do you mean with ValueMember ?
<italic>Work hard, Work effectively.
|
|
|
|
|
Hi Yulianto,
You can set a ValueMember to each item in a listbox/checkedlistbox by
using a DataTable to populate (Name,ID are column headers).
checkedListBox1.DataSource = myDataTable;
checkedListBox1.DisplayMember = "Name";
checkedListBox1.ValueMember = "ID";<--------
You can get the ValueMamber data of one selected item by using:
checkedListBox1.SelectedValue;
This works fine if you have just one item selected... but what
if you want to loop through every selected item and get the
ValueMember?
thanks,
Ron
|
|
|
|
|
foreach(object itemChecked in checkedListBox1.CheckedItems)
You will get the object, you need to convert it to CheckedListBox
((CheckedListBox)itemChecked ).ValueMember
<italic>Work hard, Work effectively.
|
|
|
|
|
Hi , I have a checked listBox control , which stores multiple items.The thing is , I should store these values and then retrieve.How could I store these values in a SqlColumn ?
( I am sorry it could be an Sql Forum question but there could be a way using C# before Sql, so I decided to post it here.)
Thanks a lot.
Bahadir Cambel.
|
|
|
|
|
Bahadir Cambel wrote:
How could I store these values in a SqlColumn ?
Well, it seems to me you want more than one column. If you want to put all the fields of a checked item in the ListBox control into one column, then you should probably put them into a comma delimited string first.
In either case, put your data into SqlParameters, like:
SqlParameter param=new SqlParameter("@foo", myFooValue);
Then add the parameter:
cmd.Parameters.Add(param);
Then do the ExecuteNonQuery call.
Of course, I'm leaving out the creation of the SqlCommand cmd variable and some other stuff, but that's not relevant to your question.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Thanks for the reply Marc, I thought in the same way , but I asked for that there may be a better solution.
What about putting values into a class/struct,and then serialize it binary and put into a binary column ? Do you have any ideas ? Is it possible ? and could it be more efficient ?
|
|
|
|
|
Bahadir Cambel wrote:
What about putting values into a class/struct,and then serialize it binary and put into a binary column ?
You could do that, but you may encounter, at some point, the need to query the DB, and then you don't have very searchable data.
Also, beware of the .NET binary formatter. It isn't very efficient. It encodes into hideous xml, actually! You'd have to do your own binary serialization if you want efficiency, but then again, you should probably rely on the server to keep things efficient, imo.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|