|
Sorry I did go there but google isnt exactly a vorpal sword.
Also your first reply was sort of vague and lead me to believe
perhaps you were referring to some more abstract use of the term
interface. Ultimately I was able to find something of value in
your link, but it required some searching.
so thanks
|
|
|
|
|
You can start here[^], but it's a moving target.
|
|
|
|
|
To reproduce, run code, open file menu, press up and down arrows to move out of menu.
Observed: Menu items are scrolled and blank items appears in end.
I need to change visibility of menu items at runtime.
How to disable such scrolling ?
Is this .NET 3.5 bug ?
Andrus.
using System.Windows.Forms;
static class Program
{
static void Main()
{
Application.Run(new Form1());
}
}
class Form1 : Form
{
public Form1()
{
var menuStrip1 = new MenuStrip();
var fileToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem });
for (int i = 0; i < 10; i++)
{
var item = new ToolStripMenuItem("Item" + i.ToString());
fileToolStripMenuItem.DropDownItems.Add(item);
if (i < 5)
item.Visible = false;
}
fileToolStripMenuItem.Text = "File";
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
}
}
Andrus
|
|
|
|
|
with Vista, Studio 2008, targetting either 2.0 or 3.5, I observe one empty menu item line
appearing either at the top or the bottom of the list. Strange indeed.
BTW: disabling the hidden items does not help things.
|
|
|
|
|
Calling Dispose() makes them invisible properly.
However I need to make them visible later, so it is not possible to use Dispose().
Andrus
|
|
|
|
|
When I need varying menus, I do one of two things:
1.
temporarily remove the items I don't need
2.
throw away all items and create all new menu items when the menu gets selected
and I know something needs a change.
BTW: just hiding items (Visible=false) is wrong anyway, what will happen to the
shortcuts (CTRL/C and the like) that got assigned to you items? Removing is OK here.
|
|
|
|
|
Just for comparison,
Same configuration, but no empty items in the menu. I've installed all possible updates so maybe there's the difference.
However, Luc had a very good point why removing items would be a better choice.
Mika
|
|
|
|
|
|
|
I have a large winforms menu system designed using Windows forms designer in MDI parent form.
Some menu items should not be visible to user who logs in.
I have also command "login as different user" in this MDI parent form which allows other user to log in without exiting main form.
For this command I need to make some other menu items visible.
How to implement Main menu visibility in this case ?
Andrus
|
|
|
|
|
Either disable the items (they remain visible, readable, but are not selectable)
or remove them temporarily, by taking them out their regular collection and keeping
them in another collection, not associated with any live menu.
|
|
|
|
|
Either disable the items (they remain visible, readable, but are not selectable)
In this case are are 50 disabled items in menu different menus. This looks ugly to user. So it is not possible.
or remove them temporarily, by taking them out their regular collection and keeping
them in another collection, not associated with any live menu.
I shoudl also member menu item position in menu tree system and placement. Where to find sample code which implements this ?
Andrus
|
|
|
|
|
I have no sample code.
You could work the other way around:
- use Designer to design the maximally populated menus;
- then programmatically remove them in globo from the main menu structure, but keeping
them around;
- and provide the appropriate subset by copying the items you want to keep into
the main menu structure again.
That way you always know what the exact population and order of the original menus was
and you can easily create any subset you want.
|
|
|
|
|
- use Designer to design the maximally populated menus;
Done.
then programmatically remove them in globo from the main menu structure, but keeping
them around
I tried in main form load
ToolStripItemCollection Copy = MainMenuStrip.Items.Clone();
but got compile error
'System.Windows.Forms.ToolStripItemCollection' does not contain a definition for 'Clone' and no extension method 'Clone' accepting a first argument of type 'System.Windows.Forms.ToolStripItemCollection' could be found (are you missing a using directive or an assembly reference?)
Andrus
|
|
|
|
|
I haven't done this with ToolStripItems yet.
There seems to be a CopyTo() that may be useful.
|
|
|
|
|
CopyTo() copies only top level menu items. Child items are not copied. So child items are destroyed i sLoad and not restored if new user logs in
How to clone whole menu tree ?
partial class MainForm : Form {
ToolStripItem[] Copy;
protected override void OnLoad(EventArgs e) {
Copy = new ToolStripItem[MainMenuStrip.Items.Count];
MainMenuStrip.Items.CopyTo(Copy, 0);
SetVisibility(MainMenuStrip.Items);
}
void NewUser_Click(object sender, EventArgs e) {
MainMenuStrip.Items.Clear();
MainMenuStrip.Items.AddRange(Copy);
Copy = new ToolStripItem[MainMenuStrip.Items.Count];
MainMenuStrip.Items.CopyTo(Copy, 0);
SetVisibility(MainMenuStrip.Items);
}
void SetVisibility(ToolStripItemCollection items)
{
foreach (ToolStripItem item in new IsolatorCollection(items))
{
if (item.Tag != null)
if ( CurrentUserShoundNotSeeThis(item.Tag))
items.Remove(item);
ToolStripDropDownItem dropItem = item as ToolStripDropDownItem;
if (dropItem != null)
SetVisibility(dropItem.DropDownItems);
}
}
Andrus
|
|
|
|
|
BTW: just hiding items (Visible=false) is wrong anyway, what will happen to the
shortcuts (CTRL/C and the like) that got assigned to you items?
I set both Visible and Enabled to false. In this case shortcuts are disabled also.
Andrus
|
|
|
|
|
first of all i would like to say that i am very new to programming and also to .net .
now i have a problem.
i have two dropdownlists:
1) dropdownlist 1- having 2 items ex: male and female
2) dropdownlist 2_ having 4 items ex: dog, cat, fish, cow.
now the problem is :
if i select male then all the four options should be visible , but if i select female then dog, cat and cow will be visible but not fish.
please send me the code both by help if items are hardcoded by itemlist and if we want to manipulate through database(sqlserver 2000).
please help me , and reply me fast.
thank you
|
|
|
|
|
As fast as I could, it might not compile tho...
HAI
CAN HAS STDIO?
I HAS A dropdown1 ITZ ARRAY
I HAS A dropdown2 ITZ ARRAY
BTW array assignments
LOL dog IN MAH dropdown2
LOL cat IN MAH dropdown2
LOL cow IN MAH dropdown2
I HAS A gender IN MAH dropdown1 ITZ YARN
GIMMEH gender
IZ gender LIEK "male"?
YARLY
BTW the male case
LOL fish IN MAH dropdown2
NOWAI
BTW the female case, no other assignment necessary
KTHX
KTHXBYE
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
if(Listbox1.Text=="Female")
{
Listbox2.Items.Clear();
ListBox2.Items.Add("dog");
ListBox2.Items.Add("cat");
ListBox2.Items.Add("cow");
}
else if(Listbox1.Text=="Male")
{
Listbox2.Items.Clear();
ListBox2.Items.Add("dog");
ListBox2.Items.Add("cat");
ListBox2.Items.Add("fish");
ListBox2.Items.Add("cow");
}
|
|
|
|
|
Is there a way to modify the start menu to add a new "expandable button" under 'all programs'. This expandable button would function like the "all programs" button but when it shows the list of programs, it will only display the applications relevant to the user's job. I've searched around but i can't find anything.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
|
The link you provided has nothing to do w/ my question. I really don't care how to change the text on the start button. And besides, nothing is impossible! This link[^] shows how to add buttons/groups to the taskbar. I am already able to get a handle to the window in which i believe the "All Programs" button is added. I am just not sure which messages to send to get a button created.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
You might tell us for which operating system you want this?
|
|
|
|
|
Hi Luc, the OS is Windows XP. Playing around with Spy++ i am able to get a handle to the window (i think it's "Desktop More Programs Pane") which the button might be added. I tried to get a handle to the window that gets expanded, but i haven't had much luck. If you'd like more information please let me know!
Don't be overcome by evil, but overcome evil with good
|
|
|
|