|
The CF_TEXT clipboard format is the same as DataFormats.Text in the .NET BCL. Both are simply defined as "Text" (actually, CF_TEXT is a pre-registered ATOM, IIRC, defined as 1).
So, as you posted before, just use dataObject.GetData(DataFormats.Text) and parse the text to get only the phone number. Because of the variability, you might consider using a string tokenizer or the System.Text.RegularExpressions.Regex class for regular expressions.
FYI, C# really has nothing to do with this. Since you're new, it's important to understand that C# is one of about 30 languages currently that target the Common Language Runtime (CLR). C# has access to the same classes as any other language. The Microsoft .NET Base Class Library (BCL) is the assemblies that comprise the .NET Framework, but any assembly can be used by any language because they all compile down to the same Intermediate Language (IL) that is contained in a module which is embedded into an assembly (which may also contain assembly attributes and embedded resources, and always has a manifest of what it contains).
So, the clipboard and drag-n-drop functionality is actually provided by the BCL assemblies (System.Windows.Forms.dll, specifically). While the same level of functionality is not exposed by the BCL classes, the OLE clipboard and drag-n-drop functionality is encapsulated and used (otherwise you wouldn't be able to drag-n-drop out of your .NET application). I'm currently developing a library that does expose all the functionality in a .NET-friendly manner, but it will be quite some time before it's done (I don't exactly have a lot of time).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
somebody can explain about SNTP Class?
thanks
Nho'c Ti`
|
|
|
|
|
This forum is for discussions about C#, not SNTP. You can read about SNTP by reading the RFC, which can be found at - among many other places - http://www.faqs.org/rfcs/rfc2030.html[^]. There are many other sources available for SNTP. Just google or something.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello.
I have red Code project articles on implementing Undo and have come to the conlusion that the best and easiest way for doing it is Undo and Redo the "Easy" Way and have found it very interesting. The question is. Can i do it in C# and if yes, does naybody have some premade code.
Only Absolute Power and Absolutely No power matters. The rest is slavery.
|
|
|
|
|
It is an interesting concept, but probably not so very well suited for the .NET world with its own memory manager and a garbage collector, also the word "easy" in the article name is in quotes for a purpose. You will be much more better of with an implementation of a "Command" OO design pattern, which will allow your app to support the same functionality but much more elegantly.
|
|
|
|
|
To display the vertical scroll bar of any control (Print Preview Control in perticular)which window message is set?
pls guide
|
|
|
|
|
A windows message is not "set" - it is sent. For controls that support it (not every control does), you can set the WS_HSCROLL (0x00100000) and WS_VSCROLL (0x00200000) window styles by overriding the CreateParams property:
protected override System.Windows.Forms.CreateParams CreaeParams
{
get
{
System.Windows.Forms.CreateParams cp = base.CreateParams;
cp.Style |= WS_HSCROLL | WS_VSCROLL;
return cp;
}
}
const int WS_HSCROLL = 0x00100000;
const int WS_VSCROLL = 0x00200000; Most controls that support scrollbars in the Windows Forms library already have properties that control these.
Again, not every control supports them. As for the Windows Common Controls, see the Windows Controls[^] documentation and reference in the MSDN Library.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It works, but the scroll bars immidiately disappear as soon as the document is displayed.
I tried in different way, as suggested by my friend
[System.Runtime.InteropServices.DllImport("user32")]
public static extern int ShowScrollBar(int hwnd, int wBar, int bShow);
private void ppcDocViewer_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
int i = ShowScrollBar((int)this.ppcDocViewer.Handle, 1, 1);
}
It works fine.
What would be the best way?
|
|
|
|
|
ShowScrollBar is a macro that does what I mentioned before. Use that if you like; if nothing else, it's less code to define.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there any way to implement object registration with a class factory similar to the static object constructors of C++? I’m trying to avoid having one location with a HUGE list of initializers.
For example this could register a type with a factory in C++
<br />
class MyNewClass<br />
{<br />
};<br />
<br />
static ClassFactory::Register<MyNewClass> gMyNewClassRegister;<br />
In C# the only way to do this that I can find is by manually calling a register function for each type which will result in long lists of using namespaces and register calls.
|
|
|
|
|
Typically, this is done using a .config file, where types (as strings, like "System.String, mscorlib") are defined. You could easily create an IConfigurationSectionHandler (or re-use an existing one like the NameValueSectionHandler ) that reads these in the first time your configuration section is accessed (it's cached after that, so changes must be to the settings class or the app must be restarted). You could, for example, read these into a class with a static property that is an IList or IDictionary (typed class, if you want) that may be read-only or read-write (if you want to change it at runtime).
When you want to create an instance of a class, you pass some token (perhaps the string name or some friendly name) and the type is created.
This is actually how much of the .NET Framework BCL works, especially in .NET 2.0 (which uses the provider pattern heavily). In our own flagship application I designed, callers pass the type of interface for which a proxy should be instantiated. The configuration class finds the type string for that interface and instantiates the proxy. All calls to the proxy are late-binding calls to the interface.
You should search CodeProject for "configuration settings" or something along those lines for examples.
In this scenario, your settings class (the instance the IConfigurationSectionHandler creates) is the factory. Registration is done by adding types to the .config file, or adding them at runtime (perhaps you want to support some built-in types that should always be present).
If you want to use this provider pattern with the new operator, you should take a look at the ContextBoundObject class documentation in the .NET Framework SDK. By attributing a derivative class with the ProxyAttribute and implementing your own RealProxy , you can intercept IConstructionCallMessage and create an appropriate type. Perhaps the constructor would take a Type or a String , and your RealProxy derivative uses that parameter to actually create that type and return it. Of course, that Type should abide by some contract - perhaps even extending the class that the caller believes they are instantiating.
You can find more information about this at MSDN[^] and here on CodeProject. Search for AOP - or aspect-oriented programming. This isn't AOP specifically, mind you, but uses concepts that are very similar (proxying calls to another context so that transform sinks can be inserted in a chain easily, which is essentially what your class factory is in this scenario).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have an application that I want to put on a network drive so everyone runs the same executable. The problem is that once it is on the network drive, I get an authentication error.
I found UB's article Understanding .NET Code Access Security and tried go through his example. I have the .snk file and I know it is loaded (if I rename it, I get a compile error) but I don't get the lock access he describes and demonstrates. I'm at a loss to this.
Two things:
1) Are there some other links available to identify what I need to do to the executable and associated .dlls to allow/control network access? Also, I got the impression I will have to configure security on each PC that accesses this file (multiple files when including dlls). This does not seem to present a very managable solution.
2) With 100+ people in the company, is there a better way to manage the executables? Right now, when an update is done, it is a process of going to each workstation and copying it down. This is the primary reason to switching to network access.
Thanks
|
|
|
|
|
dbetting wrote:
Are there some other links available to identify what I need to do to the executable and associated .dlls to allow/control network access?
I would recommend you read about Code Access Security on MSDN, they have a lot of great information, check this[^] out.
dbetting wrote:
With 100+ people in the company, is there a better way to manage the executables? Right now, when an update is done, it is a process of going to each workstation and copying it down. This is the primary reason to switching to network access.
Perform a network install, and with your users, place them in a Group, that way you can perform security checks like IPrincipal.IsInRole , etc.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi,
I've got three textbox's in my form, total(textbox1), hours(textbox2), material(textbox3). Does anybody know the event handler code to add hours(textbox2) + material(textbox3) to get a value in the total(textbox1). It must be done during runtime.
cheers
SM
|
|
|
|
|
Hey Steve I am a little vague on what you are wanting to do.
Do you plan on using the standard TextChanged event or are you trying to build your own event.
this.textBox3.TextChanged += new System.EventHandler(this.CalcTotal);
private void CalcTotal(object sender, System.EventArgs e)
{
textBox1.Text =Convert.ToString(Convert.ToDecimal(textBox2.Text) + Convert.ToDecimal(textBox3.Text));
Now if you are wanting to add the textboxes at runtime and code the event that a little more fun. Create a member variable then initialize it. Be sure and add it to the Controls collection.
private System.Windows.Forms.TextBox textBox4 = new TextBox();
private System.ComponentModel.Container components = null;
public Form2()
{// initilize it in the constructor
textBox4.Location = new System.Drawing.Point(184, 154);
textBox4.Name = "textBox4";
textBox4.TabIndex = 3;
textBox4.Text = "0.00";
textBox4.TextChanged += new System.EventHandler(this.CalcTotal);
this.Controls.Add(textBox4);
InitializeComponent();
}
I don't know if this helps but good luck.
|
|
|
|
|
Kevin
thx so much...your a star
cheers
SM
|
|
|
|
|
While I think Kevin helped you, it is important to understand that there is no specific event handler to do what you said, event handlers do just that; handle events. In your case, you might want to write a single function UpdateTotal() , that gets called when either values of your textboxes change. So when a certain event fires, you will call UpdateTotal() . This way you can perform additional error check to make sure valid data was submitted.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi Nick,
ok, so what would be the code for my example?
cheers
SM
|
|
|
|
|
stevemasters22 wrote:
ok, so what would be the code for my example?
I am not going to write the code for this example, that is for you to do. You need to look into Int32.Parse[^] and TextBox.Text[^]. The MSDN[^] is a great source for information, if you have a specific question please feel free to post it. Good luck.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Forgive me but I am very new to C# and VS.NET.
I have a number of submenu items that are created at run-time. When any of these items are clicked I want it to call the same function but with some sort of argument.
I have extended the System.EventArgs class to include a private member. Do I need to declare a delegate or can I use the System.EventHandler?
When I try declaring a delegate like this:
public delegate void OpenPortEventHandler(object sender, OpenPortEventArgs e);
And then add this eventhandler to a menu item like this:
this.OpenPort.MenuItems[index].Click += new OpenPortEventHandler(this.COM_Click);
I get this error: Cannot implicitly convert type 'Serial_Communicator.Terminal.OpenPortEventHandler' to 'System.EventHandler'
|
|
|
|
|
What you can do is subclass the MenuItem and add your event and delegate there.
class OpenPortMenuItem : MenuItem
{
public delegate void OpenPortEventHandler(object o, OpenPortEventArgs e);
public event OpenPortEventHandler PortClick;
public OpenPortMenuItem()
{
this.PortClick += new OpenPortEventHandler(OnPortClick);
}
protected override void OnClick(EventArgs e)
{
if(PortClick != null)
{
OpenPortEventArgs args = new OpenPortEventArgs();
args.Port = 80;
PortClick(this, args);
}
}
protected void OnPortClick(object sender, OpenPortEventArgs e)
{
base.OnClick(e);
}
}
class OpenPortEventArgs : EventArgs
{
private int _port;
public int Port
{
get{return _port;}
set{_port = value;}
}
public OpenPortEventArgs(){}
}
OpenPortMenuItem m = new OpenPortMenuItem();
OpenPortMenuItem m2 = new OpenPortMenuItem();
m.Click += new EventHandler(this.COM_Click);
m2.Click += new EventHandler(this.COM_Click);
this.mainMenu1.MenuItems.AddRange(new OpenPortMenuItem[] {m, m2});
private void COM_Click(object sender, OpenPortEventArgs e)
{
MenuItem m = sender as MenuItem;
if(m != null)
{
}
OpenPortEventArgs a = e as OpenPortEventArgs;
if(a != null)
{
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Nick:
I can't thank you enough. Works like a charm. I'll have to examine a little closer to see exactly what you did.
Thanks again.
-Jae
|
|
|
|
|
Nick:
I was actually able to get it working with less code that you gave me there. Any idea why the code still works when I change the class to the following:
public class OpenPortMenuItem : System.Windows.Forms.MenuItem
{
//public delegate void OpenPortEventHandler(object o, OpenPortEventArgs e);
//public event OpenPortEventHandler PortClick;
private int index;
public OpenPortMenuItem(int index)
{
this.index = index;
//this.PortClick += new OpenPortEventHandler(OnPortClick);
}
protected override void OnClick(EventArgs e)
{
//if(PortClick != null)
//{
OpenPortEventArgs args = new OpenPortEventArgs(this.index);
OnPortClick(this, args);
//}
}
protected void OnPortClick(object sender, OpenPortEventArgs e)
{
base.OnClick(e);
}
}
And I use the menuitem like this:
this.OpenPort.MenuItems.Add(index,m);
this.OpenPort.MenuItems[index].Click += new System.EventHandler(this.COM_Click);
Let me know if that check for PortClick != null is there for some sort of error catching.
-Jae
|
|
|
|
|
Jae,
The check of if(PortClick != null) checks to see if the events' internal linked-list of handlers has any registered handlers or not, otherwise there is no reason to call anything if no one is listening. Others could use your OpenPortMenuItem class and attach their own event handlers to the PortClick event.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Nick:
Does that mean that the following:
protected override void OnClick(EventArgs e)
{
if(PortClick != null)
{
OpenPortEventArgs args = new OpenPortEventArgs(this.index);
OnPortClick(this, args); //Function call
}
}
Would be better written as this:
protected override void OnClick(EventArgs e)
{
if(PortClick != null)
{
OpenPortEventArgs args = new OpenPortEventArgs(this.index);
PortClick(this, args); //Raise the event
}
}
That way anyone else who has attached delegates to the PortClick event will be triggered when the menu item is clicked?
-Jae
my blog
|
|
|
|