|
Ok, you can take the CheckBox cb and put it outside the loop if that's your only concern...
Or you yould use
if (c is CheckBox)
{
CheckBox cb = c as CheckBox;
}
I found the is keyword very handy instead of fiddling with GetType().ToString() and then comparing to the quite verbose (and thus prone to typos) fully qualified type names.
mav
|
|
|
|
|
I am writing an application to change the inputlanguage and culture using C#. I am trying to find out whether selected language is written left-to-right or right-to-left to set right-to-left property of my control accordingly. Is there any way to find this ? Please Help!!
Naqvi
|
|
|
|
|
Can anyone tell me is there any difference between the usual DOS Command Prompt and the Visual Studio.NET Command Prompt provided with the Visual studio.NET?
Can I run a C# Console application which takes Command line arugent from the Visul Studio itself without using the Command Prompt?
Thanx.....
|
|
|
|
|
The Visual Studio .NET Command Prompt just sets up the paths to all the VS and .NET tools.
Go to normal command prompt and try an run "csc" or "guidgen" if they're not in your path, they won't run. Inthe VS.NET command prompt they will. And yes you can run console apps from IDE and even pass parameters to it. Check Project->Properties
|
|
|
|
|
Thanx Roman
I tried giving command line arguments in Project->Proprties->Configuration Properties->Debugging. It works fine.
If every time I want to give a different value I have to set the value there only.
thnx again.
|
|
|
|
|
How can one replicate the Close() event with its corresponding CancelEventArgs?
I.e. how to find out from the code firing the event what the receiver set this attribute to?
Does anyone know and can help clarify this procedure to me...
|
|
|
|
|
If there's just a single event handler attached, then it's fairly easy:
In your class you need:
public delegate MyCancelHandler(bool cancel);
public event MyCancelHandler AnEventThatCanBeCancelled;
if (AnEventThatCanBeCancelled != null)
{
bool cancel = false;
AnEventThatCanBeCancelled(cancel);
if (cancel)
{
MessageBox.Show("Event has been cancelled by a listener");
}
else
{
MessageBox.Show("Event has NOT been cancelled, go on with whatever you want");
}
}
If there's more than one listener attached, then you'll only get the cancel info of the last listener notified.
In this case you'll have to go through all registered delegates (using MulticastDelegate.GetInvocationList() ) and check all of them if anyone wants to cancel your event.
Regards,
mav
|
|
|
|
|
That won't work. bool (System.Boolean ) is a value type, and you'd need to declare the delegate parameter as out or ref .
Besides, it's far easier to just reuse CancelEventHandler . Since it uses the CancelEventArgs which has a Cancel property (that will keep the value), you don't need to declare your own event.
Also, while it's not required, events should typically follow the EventHandler signature and the second parameter should (agian, not required to) derive from EventArgs . CancelEventArgs does, of course, extend this class.
If you want to know what a specific callee of the callback set the CancelEventArgs.Cancel property to, your past paragraph is correct.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Of course you're right, Heath.
This is what you get when you don't actually try out your own suggestions...
|
|
|
|
|
Hi,
I have two different type of designers e.g. a flowchart designer and a form designer, how should i integrate them in one enviroment. As each designer has its own toolbar (having different tools) and its own properties (shown in propertygrid).
What is the best approach to go with.
Thanks in advance,
Omar Rehman
|
|
|
|
|
Hi all
The help is necessary. I need in my program climb on https site.
a problem in that that it is necessary to establish the certificate from this site.
The request to those who worked with it to to give a slice of a code for work with
certificates (it'll be good if it be working)
everyone speak that X509Certificate must be used but in msdn there is no real code.
please help because I burn
|
|
|
|
|
There isn't always sample code in MSDN, so you must understand how to use the types that are documented. HttpWebRequest.ClientCertificates is an X509CertificationCollection , so obviously you need to instantiate that collection class. Since it's also an IList implementation, you can add and remove X509Certificates .
If you already have client certificates (which you can view and export in the Internet Options, Content tab), you can simply use the static X509Certificate.CreateFromCertFile method, passing the filename of the client certificate for identification to the server that you can export from Internet Options like I mentioned above.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
please give me some code if you have because i can write it by myself!!!
|
|
|
|
|
I am trying to receive the udp datagram that from
the client sended to the server port 7090,but i have some questions following.
1) How to listen to port 7090?
Should I setup a timer to scan port 7090?
2) Is there a event that start when the udp
datagram get to the server and how to
implement?
3) If many client send to the same server port 7090 in the same time.
How can I to sure which one is from where?
thanks for your help!
|
|
|
|
|
UdpClient.Receive is a blocking call, and there is no events on the UdpClient . You use it to send packets to a server or multicast group and then call UdpClient.Receive to wait for a response.
You should read the class documentation[^] for the UdpClient in the .NET Framework SDK. It contains all the information you should need plus many examples of how to use it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
can someone tell me how I can get the code below to paint the rectangle where the button is(even though it is not behind drawn(this is code to show an example of a problem I'm having, I don't want to make button invisible)... it seems that the base class has introduced a clip region where the button is. I've tried my best to remove this region(messing with the painteventargs clip region, getting a graphics object from this.CreateGraphics, etc...)... I've also tried to remove the WM_CLIPSIBLINGS from the CreateParams, but that didn't work... not sure if this is a bug in forms or I'm just missing something. Anyways, I really hope someone can help me as this is my 3rd post on this. Thanks.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
public Form1() { InitializeComponent(); }
protected override void Dispose( bool disposing )
{
if ((components != null) && (disposing)) components.Dispose();
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(96, 64);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(136, 136);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main() { Application.Run(new Form1()); }
protected override void OnPaintBackground(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), 0, 0, Width, Height);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x000F)
{
return;
}
base.WndProc (ref m);
}
}
|
|
|
|
|
It's not a good idea to simply ignore WM_PAINT (0x000f). Instead, add the following to your constructor:
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true); This forces double-buffered painting to occur all within your OnPaint override. See the ControlStyles enumeration documentation in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
this doesn't seem to work because I want to do all the double buffering. I do not want the parent at all to do anything for the child controls, not even call them to be painted(well, doesn't really matter)... specially don't want them to draw some black filled rectangles for there background. The only way I can get close to getting what I want is to override the WM_PAINT and in it, call my Painting functions directly. The only problem with this, is when I use the control, I get a flash of the black rectangle. So there must be more window messages that are being called that do this "stupid" thing. I know resize and move does it. I've tried setting what you said in both the form's constructor and the childs and neither work. Not sure why, but the WndProc's base has some code in there that is really screwing things up for me... I don't like to override the WM_PAINT, but seems to be the only probable solution at the moment.
this is the process: In the Main form, create a bitmap and in the OnPaintBackground draw the bitmap to window. In the Controls OnPaint, pass the bitmap to the base controls' OnPaint so we can let windows handle drawing the control to the bitmap(basicaly base.OnPaint(new PaintEventArgs(G, clip)) where G is the graphics object of the bitmap and clip is the clip rectangle)
all this code works smoothly, except for those damn black rectangles over the controls.
Anyways, hopefully you understand the problem? I'm sure theres a simple solution(atleast I hope), and thanks for helping...
|
|
|
|
|
I understand the problem. In your override to OnPaint , just don't call base.OnPaint . In the base class, WM_PAINT is already being caught and OnPaint (indirectly) is being called. In Control.WndProc , after calling the internal WmPaint (which calls OnPaint after some setup code) execution is returned to the caller. Since WndProc is the WindowProc for the window class, WM_PAINT shouldn't be sent to the control without first going through OnPaint , which means you control all painting. As I said before, just don't call base.OnPaint and all the painting is done by you.
There are many articles here on CodeProject about painting your own buttons. If all you're trying to do is avoid having the black rectangle painted, 1) drawing a button yourself (completely) wouldn't be that hard (if you want the raised look, use state variables that you set in the mouse event handlers by overriding the respective OnEventName methods), and 2) you should be able to set the clipping region within your implementation. Since you now control all the painting, you decide what gets drawn and what doesn't.
If you were to set the clipping region this way, then you could eliminate the area that the black border would cover and then call base.OnPaint . OnPaintBackground isn't necessary since setting ControlStyles.AllPaintingInWmPaint to true using SetStyle directs all painting to be done in the WM_PAINT handler.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
is there a way to change the max image size to more than 256?
|
|
|
|
|
No. If you want an ImageList -like class to hold more, you'll need to develop your own; but I warn you that this would be very resource intensive.
You might consider, instead, to cache those images to disk since they would require a lot of memory, of which the CLR already requires quite a bit plus the more assemblies you use, the more memory is required (this is true of any application that imports libraries).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi all,
i'm tring to write a progarm to manage my network cards (wire/wireless).
I want to disable the wire card and enable the wireless (and reverse).
from my research i understand that wmi is not providing this feature, only to disble DHCP or give 0.0.0.0 in the IP.
i need to diable(and enable)throw c#.
does any one know how ?
pls help ASAP.
10x
liron shryer
Nice systems.
|
|
|
|
|
My console project is named UsingConfigSettings in C#, and wanted to store the database connection in an application config file. I added an application config named "UsingConfigSettings.exe.config" in my project. Here is its contents:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="constring" value="server=localhost;database=Northwind;uid=sa;pwd=;"/>
</appSettings>
</configuration>
I even copied it in the bin\debug folder in my C# console application, but it still doesn't work. I acccess it in the console as:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public class UsingConfigSettings
{
public static void Main()
{
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["constring"]);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM Customers";
cmd.Connection = con;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read())
{
Console.WriteLine("{0} - {1}", reader.GetString(0), reader.GetString(1));
}
con.Close();
Console.ReadLine();
}
}
but it won't work, it always issued a message of:
"An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: The ConnectionString property has not been initialized."
If I don't use any config file, and replace the code above, it works fine:
SqlConnection con = new SqlConnection("server=localhost;database=Northwind;uid=sa;pwd=;");
Please help.
|
|
|
|
|
If you want the .config file to be copied automatically to the target directory, create a file named app.config in the root of your project. VS.NET will automatically rename this according to your executable name and copy it into the bin\Debug or bin\Release directory along with the application.
Make sure that when you run the application, you are running the one in the target directory. If you hit F5 (debug), the application is actually run out of the obj\Debug directory. Using the method I described above will make sure the .config file is renamed and copied to the obj\Debug directory as well (which is actually the target directory).
Everything else you have is right.
FYI, never use sa without a password! Since you're using SQL, either use SSPI (don't specify uid or password, and instead use Integrated Security=SSPI and add your Windows login username or group to SQL Server), or set up a different user account. Give sa a password anyway. This is like having the administrator account with no password as well - it's a big hole in security.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am wrapping a Dll function with managed code and am confused about the equivalent of pointers and the & symbol in C. I am working with two C functions wrapped in a Dllimport:
[DllImport("msg.dll",CharSet=CharSet.Ansi)]
public static extern int MsgConnect (int lAPIVersion, string lpcszTopic, ref OPERATOR lpOperator, ref IntPtr lphContext);
Where the C functional prorotype was:
MSGAPIFUNCTION MsgConnect(long lMsgAPIVersion, const char *lpcszTopic, LPOPERATOR lpOperator, MSGHANDLE *lphContext);
The lphContext is a handle, specified in C as:
typedef void *MSGHANDLE
I am trying to import this function:
MSGAPIFUNCTION MsgStartMessage(MSGHANDLE hContext, const char *lpcszActivityName, const char *lpcszMsgName, int bOriginatorVerified)
I have defined it as:
[DllImport("msg.dll",CharSet=CharSet.Ansi)]
public static extern int MsgStartMessage (ref IntPtr hContext, ref string lpcszActivityName, ref string lpcszMsgName, int bOriginatorVerified);
Note it is using the variable itself, not a pointer to it like the previous prototype. I implemented the pointer as IntPtr, not sure how to implement this - do I need to convert it to an Int?
Thanks in advance.
|
|
|
|
|