|
I know MDI's are supposed to be just containers and they can't have contents other than maybe a menustrip.
But I'd like to have a main window with buttons, images and other stuff, and then smaller windows that open inside it.
Is there any way to make this main form and MDI and get the MDI contents (buttons and everything else) sent to back every time a new form is opened? I tried placing all my main form contents in a panel and then call the panel.sendToBack() method when a new form is opened, but it sends it SO back that it ends up in the back of my screen, even behind the main form
I know an option is to show the forms as modal dialogs, but I'm supposed to let the user work with more than one window at a time.
Any hints?
Thanks
|
|
|
|
|
Look in your parent form Control collection. You'll find a control of type MdiClient that hosts all of your child windows. You get at it and use it just like any other control from your code, even undock it and resize it. You just can't get at it with the designer. Docs on it are here[^].
|
|
|
|
|
Thanks for the tip
Although I'm not sure about what to do with the MdiClient control once I find it in the collection.
I need to make it stay back while the user works with the child forms. Right now, only the form stays back but the panel inside it stays on top, covering the child forms when they open.
modified on Friday, January 21, 2011 2:21 PM
|
|
|
|
|
You cannot make the MdiClient appear on top of other controls on the parent form. It'll stay behind all other controls on the Mdi Parent form. But, as I said, you can get a reference to the control and undock it and move it over to the side to make room for you other form controls. Something like:
foreach (Control c in this.Controls) {
if (c is MdiClient) {
MdiClient mdic = (MdiClient)c;
mdic.Dock = DockStyle.None;
mdic.Anchor = AnchorStyles.None;
mdic.BackColor = Color.Blue;
mdic.Location = new Point(40, 40);
mdic.Size = new Size(400, 400);
}
}
|
|
|
|
|
If you dock the panel to top, any child form that you open should open over the top or under it in the form container.
|
|
|
|
|
Hi all,
I have a ToolStripMenuItem in my MenuStrip . I've added a few ToolStripMenuItem s as dropdown items at design time. Now I'd like to copy that list of dropdown items to a ToolStripDropDownButton at runtime but I seem to move the items from the ToolStripMenuItem to the ToolStripDropDownButton , not duplicate it.
Here is the code I'm using:
ToolStripItem[] newitems = new ToolStripItem[myToolStripMenuItem.DropDownItems.Count];
myToolStripMenuItem.DropDownItems.CopyTo(newitems, 0);
myToolStripDropDownButton.DropDownItems.AddRange(newitems);
But the problem is that as soon as the last line executes the DropDownItems collection for the ToolStripMenuItem becomes empty. Does anyone have advice for me? Thanks in advance.
|
|
|
|
|
I think your issue is that your array is essentially storing references of each button - so your last line is in effect adding the exact same buttons (and will automatically become a "move")
What you should do is...
- Iterate the existing list of items
- create new items based on the existing ones
- add the new one to where you want them
this should provide a "copy" for you
foreach(ToolStripItem item in myToolStripMenuItem.DropDownItem){
ToolStripItem newItem = new ToolStripItem();
myToolStripDropDownButton.DropDownItems.Add(newItem);
}
return 5;
|
|
|
|
|
First of all, the ToolStripItem() constructor is protected so your first line in the foreach loop is already going to cause a problem. Secondly, it's that comment line of yours that is the big headache. It means I have to copy the event handler, the tooltip text and everything.
Is it a fact that a ToolStripItem can belong to only one DropDownItem collection?
|
|
|
|
|
The code was more for a idea than actual use - I have not worked with them for a while and forget the actual usage but I have created them dynamically is the past so I know you can create an instance somehow.
Again, its been a while so I didn't know if there was a 'clone' type of function perhaps. But considering it is a button surely you will only need to copy a few key values such as Text, Icon (if any) and the Click eventHandler.
ToolStripItem is a Control, and a Control can only have one parent Control - Basically what you have inadvertently ended up doing is changing the parent control - this is why it appears to "Move" (I don't know much about how this happens 'behind the scenes' thou)
return 5;
|
|
|
|
|
Had a little play now.. are your items all the same type? i.e. ToolStripButton as you can create all those controls.
This is pretty messy but just an idea of what I was playing with...
foreach (ToolStripItem item in toolStripDropDownButton1.DropDownItems)
{
ToolStripItem newItem = new ToolStripMenuItem();
if (item is ToolStripComboBox)
newItem = new ToolStripComboBox();
else if (item is ToolStripTextBox)
newItem = new ToolStripTextBox();
newItem.Text = item.Text;
toolStripDropDownButton2.DropDownItems.Add(newItem);
}
return 5;
|
|
|
|
|
Hi
i want to implement deisgner at runTime in my app, to do this i 've create a simple win app and write this code to my form :
public partial class Form1 : Form
{
IServiceContainer isc;
DesignSurface ds;
IDesignerHost idh;
ISelectionService iss;
IToolboxUser itu;
MyToolBox toolbox;
public Form1()
{
isc = new ServiceContainer();
ds = new DesignSurface(isc);
ds.BeginLoad(typeof(Form));
idh = (IDesignerHost)ds.GetService(typeof(IDesignerHost));
iss = (ISelectionService)ds.GetService(typeof(ISelectionService));
itu = (IToolboxUser)idh.GetDesigner(idh.RootComponent);
InitializeComponent();
iss.SelectionChanged += new EventHandler(iss_SelectionChanged);
}
private void Form1_Load(object sender, EventArgs e)
{
toolbox = new MyToolBox();
toolbox.Dock = DockStyle.Fill;
splitContainer1.Panel1.Controls.Add(toolbox);
isc.AddService(typeof(IToolboxService), toolbox);
Control c = ds.View as Control;
c.Parent = this.splitContainer2.Panel1;
c.Dock = DockStyle.Fill;
}
private void iss_SelectionChanged(object sender, EventArgs e)
{
propertyGrid1.SelectedObject = iss.PrimarySelection;
}
}
and also create a new class named 'ToolboxServiceImp' which inherits from ListBox and IToolboxService as follow :
Please download my sample app from http://cid-1490cc59dd735cbf.office.live.com/self.aspx/.Public/Designer2.rar
my problem is that, at runTime when i drag & drop a control from my toolbox on the form, i got this error :
Error
---------------------------
Unable to cast object of type 'System.RuntimeType' to type 'System.Drawing.Design.ToolboxItem'.
---------------------------
OK
also, when i click on form, i got this error and designer become corrupt :
Error
---------------------------
The control System.Windows.Forms.Form has thrown an unhandled exception in the designer and has been disabled.
Exception:
Unable to cast object of type 'System.RuntimeType' to type 'System.Drawing.Design.ToolboxItem'.
Stack trace:
---------------------------
OK
where is my problem and how to solve it ?
thanks in advance
|
|
|
|
|
I don't plan to download your app, but I can guess that somewhere in your code you are trying to cast some object to a ToolboxItem , that does not have that class in its object hierarchy. You need to create the object of the correct type first.
I must get a clever new signature for 2011.
|
|
|
|
|
|
hdv212 wrote: do u have problem to download from this link ?
Firstly, I do not download from external links. Secondly, I cannot unpack .rar files.
hdv212 wrote: i found several example and source codes to demonstrate this, but all of them create a some new classes and write more complex code.
I don't know what your experience level is, but mine is nowhere good enough to advise on the Microsoft sample.
I must get a clever new signature for 2011.
|
|
|
|
|
Hi
do u have problem to download my sample file ?
do u have live account ?
|
|
|
|
|
No to both questions. But as I said above, I don't have anything else to suggest to you.
I must get a clever new signature for 2011.
|
|
|
|
|
If you are interested in this sort of thing, you might want to look at the source for SharpDevelop[^] to see how they do it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
|
|
|
|
|
|
hdv212 wrote: all of them create a some new classes and write more complex code.
It is a complex topic.
If you are looking for some simpler implementations, then maybe look at things like UML designers or Flow Chart designers. There are a fair few of those out there.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
|
|
|
|
|
Hi!!
i'm getting this error when i try to share screen from my notebook connected to the router using wifi n my pc by ethernet
"System.ArgumentException: Value does not fall within the expected range.
at RDPCOMAPILib.IRDPSRAPIViewer.Connect(String bstrConnectionString, String bstrName, String bstrPassword)
at AxRDPCOMAPILib.AxRDPViewer.Connect(String bstrConnectionString, String bstrName, String bstrPassword)"
this error comes each time i try to connect it
axRDPviewer.connect(Connstring,"user1", "");
I cant get this corrected...
It works perfect when i do it on my pc
but aint working when try to share my notebook screen...
the Connstring is being sent by Tcp message(Send and receive)...
Can u tell me where is the source of the problem... How can i take care of this???
|
|
|
|
|
Can you connect to your notebook when you use Microsoft's Remote Desktop? That's a good way to find out where the problem is located: e.g. remote access not allowed on your notebook, empty passwords for remote access not accepted...
|
|
|
|
|
when im using that RDPCOMAPILib, the aero style dosen't working ! how can we solve that problem!? can somebody help me ?
|
|
|
|
|
Hello Experts,
I would like to ask if what's wrong with my program. I have created 1 client and 1 server that will accept the message
of the client but I got this error.
Cross-thread operation not valid: Control 'lbConnections' accessed from a thread other than the thread it was created on.
For more details here is my code for the Client that send message to server.
using System;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
namespace UDP_Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
UdpClient udpClient = new UdpClient();
udpClient.Connect(tbHost.Text, 8080);
Byte[] sendBytes = Encoding.ASCII.GetBytes("Hello World?");
udpClient.Send(sendBytes, sendBytes.Length);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Here also is the code to my server which were I got the error thats is mention above.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net;
using System.Net.Sockets;
namespace UDP_Server
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void serverThread()
{
UdpClient udpClient = new UdpClient(8080);
while (true)
{
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint);
string returnData = Encoding.ASCII.GetString(receiveBytes);
lbConnections.Items.Add(RemoteIpEndPoint.Address.ToString() + ":" +
returnData.ToString()
);
}
}
private void Form1_Load(object sender, EventArgs e)
{
Thread thdUDPServer = new Thread(new
ThreadStart(serverThread));
thdUDPServer.Start();
}
}
}
Any comments or suggestion to help is kindly appreciated.
Thanks,
DAN
|
|
|
|
|
|
I have 600 xml files and I need to search through 50000 xml files to see which of those 600 exist in the 50000.
I have tried directory.getfiles and it's taking so long I could do it faster by hand I believe.
Does anyone have any ideas on how to do this efficiently? Thanks for reading.
|
|
|
|