|
What exactly do you want to know? To accomplish docking is not a trivial task. Although you mentioned you don't want a complete control library I suggest looking at this[^] article. You can look into the code and learn everything you need.
|
|
|
|
|
Spliting the Area Partition of polygon(suppose in a polygon there is rectangle,triangle,Curve) I want area of rectangle,area of triangle,Area of Curve separatly to display. please help me.actually i am displaying as a whole.
i.e i have written one method(formule) in that it will take care of displaying the area of polygon.but now i want individually(spliting separatly for all)
For any irregular polygon shape it should show separatly for each shape.
Its very urgent.
Thanks & Regards
Satya
satya
|
|
|
|
|
In VB6 i could instantiate a class in a module as public and this would become global to the entire application. This was useful for a settings class where the settings were loaded from a file when the app started, then classes would share these settings and modify them, then the settings file would updated when the app closed.
Is there a way to do similar in C#? Where do i need to put the settings class so that it is global to all other classes in a namespace?
|
|
|
|
|
I use a class to hold all my "global" settings which i load on application startup. These values are accessable from anywhere in the app. Heres how you do it:
1) Create a class which is public
2) Add public static variables where you will store your settings.
public class Globals<br />
{<br />
public static bool bBoolvalue;<br />
public static string sStringValue;<br />
<br />
public Globals()<br />
{<br />
}<br />
}
3) Then when you app starts up - just assign values to these variables
eg: Globals.sStringValue = "This is a string";
4) This variable will now contain the assigned value and because it is public static you will be able to reference it from anywhere in your app eg: string sTest = Globals.sStringValue;
Hope this helps,
Cheers
Craig
** I'd rather try and fail than fail to try **
|
|
|
|
|
Craig,
Thanks for the advice. Coming from VB6, i did not use static all that much. I took your static idea one step further and used it with properties and methods so i could duplicate what i did in VB6. It works!
|
|
|
|
|
This is my situation.
I am creating an instant messenger
I have a main method which calls application.run(new form1())
This launches my main form.
I start another thread in my form1 constructor that sits in the background and soley listens for incoming connections
code:
public form1()
{
InitializeComponent()
Thread t = new Thread(new ThreadStart(ListenNewConnections));
t.Start();
}
When thread t finally gets a new connection that thread itself shoots off another thread "A"
to handle that particular connection thru out its life span. Once that connection is done so is the thread.
Now when thread "A" is handling a specific connection I want it to create a form - this is where the problem starts.
1st thing i did
newform.Show() - creates a blank form and when mouse over u get hour glass
I think the reason for this is because it is not starting on the main thread for message pumping.
Ok so second thing i do is use a delegate
this.BeginInvoke(new createFormdelegate(createForm)); //create form method simply initializes a new form and calls newform.Show().
but when i debug it stops at the this.BeginInvoke line an gives me this error
"Invoke or BeginInvoke cannot be called on a control until the window handle has been created."
I know i am doing something wrong. Maybe my c# logical thinking is off i dont know.
Please help
Thanks in advance
Kourvoisier
|
|
|
|
|
This being your worker thread:
private static void ShowMyForm()
{
frmMyForm frmg = new frmMyForm();
Application.Run(frm);
}
If you want to make any calls that are thread dependant (on the window handle), like calling from one thread to another to set the focus of a control, that is when you use BeginInvoke. As the error points out, you can only call BeginInvoke when all handles are created.
Jon Humphreys
ActivePlanet Software
Bangkok, Thailand
|
|
|
|
|
I dont understand?
1> what is the window handle? how do i know it is created? how do i create a handle?
jonny5 wrote: private static void ShowMyForm()
{
frmMyForm frmg = new frmMyForm();
Application.Run(frm);
}
Are you telling me to call Application.Run(newForm) everytime i create a new form.
Keep in mine everytime a new connection comes in a new thread and form is created to handle
that connection and communication between the two endpoints.
I thought Application.Run() was to be only called once???
jonny5 wrote: If you want to make any calls that are thread dependant (on the window handle), like calling from one thread to another to set the focus of a control, that is when you use BeginInvoke. As the error points out, you can only call BeginInvoke when all handles are created.
I thought that is what i was doing in the code i showed...maybe not could you explain because
i was trying to create and set focus the new form with the BeginInvoke.
please help still confused.
Thanks alot!
Kourvoisier
|
|
|
|
|
anyone out there? know about this stuff
|
|
|
|
|
Hi there. I hope that this code helps. It starts a thread in the main form's constructor and, then, when a new connection gets accepted, opens a new child form.
using System;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespace FormsSpawnedByThreads
{
public class MainForm : Form
{
public MainForm() : base()
{
Text = "Spawn Some Forms";
Height = 150;
Width = 300;
Button b = new Button();
b.Text = "Connect";
b.Top = ( Height - b.Height ) / 2 - ( b.Height / 2 );
b.Left = ( Width- b.Width ) / 2;
b.Click += new EventHandler( b_Click );
Controls.Add( b );
Thread t = new Thread( new ThreadStart( ListenNewConnections ) );
t.IsBackground = true;
t.Name = "Main Listener";
t.Start();
clients = new TcpClient[ 5 ];
Closing += new System.ComponentModel.CancelEventHandler( MainForm_Closing );
}
private void ListenNewConnections()
{
IPEndPoint endPoint = new IPEndPoint( 0x7F000001, 5050 );
listener = new TcpListener( 5050 );
listener.Start();
while( true )
{
listener.AcceptTcpClient();
ChildForm cf = new ChildForm();
cf.Show();
}
}
private void b_Click( object sender, EventArgs e )
{
clients[ clientIndex++ ] = new TcpClient( "localhost", 5050 );
if( clientIndex == 5 )
{
Controls[ 0 ].Enabled = false;
}
}
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if( listener != null )
{
listener.Stop();
}
}
private TcpClient[] clients;
private int clientIndex;
private TcpListener listener;
[STAThread]
public static void Main()
{
Application.Run( new MainForm() );
}
}
public class ChildForm : Form
{
public ChildForm() : base()
{
}
}
}
"we must lose precision to make significant
statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I reread your post and you wanted to spawn threads for the connections, as well. Try the following code to do that, too. I hope that helps.
using System;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespace FormsSpawnedByThreads
{
public class MainForm : Form
{
public MainForm() : base()
{
Text = "Spawn Some Forms";
Height = 150;
Width = 300;
Button b = new Button();
b.Text = "Connect";
b.Top = ( Height - b.Height ) / 2 - ( b.Height / 2 );
b.Left = ( Width- b.Width ) / 2;
b.Click += new EventHandler( b_Click );
Controls.Add( b );
Thread t = new Thread( new ThreadStart( ListenNewConnections ) );
t.IsBackground = true;
t.Name = "Main Listener";
t.Start();
clients = new TcpClient[ 5 ];
Closing += new System.ComponentModel.CancelEventHandler( MainForm_Closing );
}
private void ListenNewConnections()
{
IPEndPoint endPoint = new IPEndPoint( IPAddress.Parse( "127.0.0.1" ), 5555 );
listener = new TcpListener( endPoint );
listener.Start();
while( true )
{
try
{
TcpClient client = listener.AcceptTcpClient();
this.Invoke( new HandleNewConnection( OpenChildForm ), new object[] { client } );
}
catch( SocketException ) {}
}
}
private delegate void HandleNewConnection( TcpClient client );
private void OpenChildForm( TcpClient client )
{
ChildForm cf = new ChildForm( client );
cf.Show();
}
private void b_Click( object sender, EventArgs e )
{
clients[ clientIndex++ ] = new TcpClient( "127.0.0.1", 5555 );
if( clientIndex == 5 )
{
Controls[ 0 ].Enabled = false;
}
}
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if( listener != null )
{
listener.Stop();
}
}
private TcpClient[] clients;
private int clientIndex;
private TcpListener listener;
[STAThread]
public static void Main()
{
Application.Run( new MainForm() );
}
}
public class ChildForm : Form
{
public ChildForm( TcpClient client ) : base()
{
c = client;
Closing += new System.ComponentModel.CancelEventHandler( ChildForm_Closing );
}
private void ChildForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
c.Close();
}
private TcpClient c;
}
}
"we must lose precision to make significant
statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thanks for responding tho i have already come up with a solution very similar to the one you have.
The major difference is that i use sockets instead of tcplisteners(i have learned you can do much more with that class).
I do run into a major problem tho.
Main form created good and i create a new thread specifically to listen for incoming connections
works great.
New connection comes in and i spawn off a new thread for it and create a form perfect.
but when i try to add or write data to that form's text box using form.textbox.text
""""I GET THIS ERROR AGAIN""""
"Invoke or BeginInvoke cannot be called on a control until the window handle has been created."
I use the beginInvoke(new delegate(method), {object [], String s}) to call a method
that changes the textbox to display the message that has been received on the specific connection thread.
I am able to add data to the text box on the main form but not the connection specific form
created on the connection specific thread.
Thanks hopes this all makes since
Kourvoisier
|
|
|
|
|
I agree with you: the Socket class has much more functionality. If you can bear with me, though, I modified my last example with the TcpLiseners to handle actual messages passed into the child forms.
using System;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Windows.Forms;
namespace FormsSpawnedByThreads
{
public class MainForm : Form
{
public MainForm() : base()
{
Text = "Spawn Some Forms";
Height = 150;
Width = 300;
Button b = new Button();
b.Text = "Connect";
b.Top = ( Height - b.Height ) / 2 - ( b.Height / 2 );
b.Left = ( Width- b.Width ) / 2;
b.Click += new EventHandler( b_Click );
Controls.Add( b );
Thread t = new Thread( new ThreadStart( ListenNewConnections ) );
t.IsBackground = true;
t.Name = "Main Listener";
t.Start();
clients = new TcpClient[ 5 ];
Closing += new System.ComponentModel.CancelEventHandler( MainForm_Closing );
}
private void ListenNewConnections()
{
IPEndPoint endPoint = new IPEndPoint( IPAddress.Parse( "127.0.0.1" ), 5555 );
listener = new TcpListener( endPoint );
listener.Start();
while( true )
{
try
{
TcpClient client = listener.AcceptTcpClient();
this.Invoke( new HandleNewConnection( OpenChildForm ), new object[] { client } );
}
catch( Exception ) {}
}
}
private delegate void HandleNewConnection( TcpClient client );
private void OpenChildForm( TcpClient client )
{
ChildForm cf = new ChildForm( client );
cf.Show();
}
private void b_Click( object sender, EventArgs e )
{
clients[ clientIndex ] = new TcpClient( "127.0.0.1", 5555 );
byte[] b = System.Text.Encoding.ASCII.GetBytes( message );
clients[ clientIndex ].GetStream().Write( b, 0, b.Length );
clientIndex++;
if( clientIndex == 5 )
{
Controls[ 0 ].Enabled = false;
}
}
private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if( listener != null )
{
listener.Stop();
}
}
private TcpClient[] clients;
private int clientIndex;
private TcpListener listener;
[STAThread]
public static void Main()
{
Application.Run( new MainForm() );
}
private string message = "It was many and many a year ago in a kingdom by the sea\n" +
"Where a maiden there lived whom you may know by the name of Annabel Lee.\n" +
"And, this maiden, she lived with no other thought than to love and be loved by me.";
}
public class ChildForm : Form
{
public ChildForm( TcpClient client ) : base()
{
Label l = new Label();
l.Dock = DockStyle.Fill;
Controls.Add( l );
c = client;
Closing += new System.ComponentModel.CancelEventHandler( ChildForm_Closing );
buffer = new byte[ 256 ];
Thread t = new Thread( new ThreadStart( HandleConnection ) );
t.Start();
}
private void HandleConnection()
{
string s = null;
NetworkStream cnxStream = c.GetStream();
int len;
try
{
while( ( len = cnxStream.Read( buffer, 0, 256 ) ) > -1 )
{
Controls[ 0 ].Text += System.Text.Encoding.ASCII.GetString( buffer, 0, len );
}
}
catch( Exception ){}
}
private void ChildForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
c.Close();
}
private byte[] buffer;
private TcpClient c;
}
}
"we must lose precision to make significant
statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Just curious if this happens to you...
my machine seems to drastically drag when i start running the 2nd thread
Both threads are continously running in the loop
while(true)
{
if Connection is Pending then
Accept Socket
}
one is listening for new connections and the other listening with a direct connection
Is this best practice for listening on sockets..... (running loops like this)
How do yahoo instant messengers handle listening on sockets?
what about AOL messengers?
Is there another way of handling this w/o loops?
do they all have loops running like this....
just curious
Kourvoisier
-- modified at 18:19 Monday 14th November, 2005
|
|
|
|
|
How can I set a form's owner to be a window outside my application?
I have a form which I want to hover in front of a specific window. The target window is not a form in my application; it is a standard windows window (type "Overlapped.") I have written user32.dll calls to get the target window's handle and position; I position my form in the appropriate place on the screen. However, to ensure that my form stays visibly in front of the target window, I have had to set it to be Always in Front.
This is a kludge, because the form is also in front of any other windows I may open, which is inappropriate. I only want my form to stay in front of the target window.
I can manually play with the z-order to ensure that my form is front of the target window and no other, but it would be more elegant to set the target window to be the owner of my form's window and let the system deal with the rest.
I understand that the user32.dll function CreateWindowEx can only set the owner of a window at creation time. I can provide the handle when I create the form, but I have been unable to divine a way to provide it. SetParent will allow me to change the parent window, but the new parent must belong to the same application.
.Net allows me to change the owner of a form I create, but only lets me change it to another .Net form; I can not find a way to user the window handle I have.
Any suggestions?
|
|
|
|
|
Basically, you can't do this. You can only set the owner to a window in your own process. You can't set it to be owned by a window in another process.
You might want to do some research into "DLL Injection" to get around this limitation. In theory, your application injects code into another process so that that code could create the new window and assign it's parent to the window you want. In theory...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Update to this old thread -- I've learned you CAN do this.
When you use SetParent on a window against a window in another process, the other window does not become the Parent, but it DOES become the Owner, making your window an Owned window.
The resulting behavior is that the owned window always appears in front of the owner (z-order wise), and will be minimized when the owner is minimized.
The owned window will not MOVE with the owner, however. That still has to be arranged otherwise.
Also, when the owned window overlaps the owner, you must be careful with your code when hiding/showing things - the owner, which is hidden, will not always refresh itself appropriately, since the owned window can't pass invalidate messages to it as a parent.
|
|
|
|
|
I may have misread your original post, but it doesn't sound like you got the effect you were looking for. You've gotten something else LIKE what you were describing though, with LOTS of problems.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Actually, I'm in pretty good shape. . .
I already have separate code which runs on a timer loop which checks the target window positions and moves my overlays to match. I've written code to adjust the z-order on each pass, but that looked kludgy because my overlays would disappear and then reappear every time the target windows were clicked (they would come to the fore, and then my overlay would be brought back in front.) I could avoid the blinking by setting them TopMost, but then my overlays would cause problem when windows are overlapped; any window opened in front, like a browser, would have my overlays popping through.
This solution fixes the z-order problem entirely, does not cause blinking or pop-through, and does not even require my code to do anything - windows handles the z-order processing efficiently for me.
The one problem - that of a failed refresh if I minimize one of my overlays - is not a major problem to me. It was only causing a problem when I hid an overlay window after some third window was interposed between the target window and the owned window, which is a rare condition (once I ensured that my own application didn't do this to me! When switching overlays, I needed to ensure I was hiding the old before showing the new, which is a simple fix.)
If, in some other circumstance, the condition isn't rare, the fix is a simple matter of adjusting the .Hide() call; it should include a SendMessage call which sends an invalidation method to the owner window. Voila!
|
|
|
|
|
hi there!
can i know how to set the date format of the calendar in a datetimepicker?
actually i know it can be set in the regional settings of your machine but how about during run-time?
any suggestions or ideas will be very much appreciated!
tnx in advance!
|
|
|
|
|
Hi
public void SetMyCustomFormat()
{
// Set the Format type and the CustomFormat string.
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
}
Hope it helps
|
|
|
|
|
hello!
I already tried that before i post and it only change the text of the datetimepicker. the calendar still has the format that is set on your regional settings.
anyway, tnx for the reply!
|
|
|
|
|
What is static and Dynamic Assemblies?
What is the use of these Assemblies in our project ?
|
|
|
|
|
This is a forum for asking for specific help with programming questions, usually requiring code, and a description of a problem.
Google is a tool which can be used for general research, including but not limited to, homework.
|
|
|
|
|
Hi.
I am working on a project in which I need to encrypt data I am storing in MySql Database.There are many codes available on Internet but most of them are in PHP and I have to encrypt data in C# windows application .Any help please.
Thank you.
|
|
|
|