|
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.
|
|
|
|
|
Hi, I suggest you:
1. use Directory.EnumerateFiles() to avoid the full list in memory
2. which requires .NET 4.0
3. calculate a hash value for each of those files in the small set, storing them in a Dictionary<filename,hashvalue>
4. iterate over the files in the large set, calculating their hash value, then comparing the file content with the files from the small set that have matching hash values.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hi Luc,
Thanks for the reply, I can't use 4.0 yet, only 3.5
|
|
|
|
|
Without .NET 4.0 you have two choices:
1. use Directory.GetFiles()
2. use Win32 functions (GetFirstFile, GetNextFile) through P/Invoke.
I would opt for 1 until proven too inefficient.
There is actually a third way: assuming all filenames start with a letter and all letters have comparable probability, use a loop and the filtered version of GetFiles, i.e. first get all names matching a*, then b*, etc; that way you never have all of them at once.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Good thinking!
return 5;
|
|
|
|
|
A quick test on my system showed Directory.GetFiles took only 215 milliseconds to get 50000 files and Array.Contains took 277 milliseconds to find 600 filenames. Perhaps you have something else happening.
This was assuming you were searching for matched files names not content.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark,
Thanks for testing that locally, do you mind pasting some code?
I can do this locally, but would prefer to do it over the network, are you iterating locally or remotely?
|
|
|
|
|
There's your problem. You failed to indicate in you original post that you were accessing the files over a network. Of course it may be slow depending on local conditions, network usage, latency, etc.
turbosupramk3 wrote: do you mind pasting some code?
What code you need? What part can't you figure out?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Well it can be done either way, it does not have to be over the network, it seemed terribly slow in either circumstance, of course much slower over the network than locally, but terribly slow locally as well.
|
|
|
|