|
I am recently curious about the process of writing your own toolbox controls. Let's take a basic approach and say I wanted to write a textbox control that was always multi-line with both scrollbars. I want to have all the events, properties and such.
How do you wire up events so that when you drag the textbox onto the form and double-click it the IDE goes to the correct handler or default handler like in the case of a button it's the Button_Click. How do I make my own button control and when I double-click it in the IDE have it go instead to Button_MouseDown or something else entirely? How do you add events for the IDE and design time?
I'd google this I just don't know what search terms to use. I've tried and failed.
|
|
|
|
|
code-frog wrote: How do you wire up events so that when you drag the textbox onto the form and double-click it the IDE goes to the correct handler or default handler like in the case of a button it's the Button_Click.
If your control is derived from Button control, this should be happening automatically.
code-frog wrote: How do I make my own button control and when I double-click it in the IDE have it go instead to Button_MouseDown or something else entirely?
If I remember correctly, DefaultEventAttribute[^] should do the trick.
code-frog wrote: How do you add events for the IDE and design time?
IDE should show up any public events that your control provides without doing anything special.
Best wishes,
Navaneeth
|
|
|
|
|
Hi
I am building an application in C# which needs to take direction from a Delphi app.
I am having quite a time adding a socket connection to the C# app using Net.Sockets.
I've searched copiously, but all examples I have found are for standalone socket connections.
Could someone point me to an example app that includes a socket connection to recieve infomation.
I am looking at a socket connection as I don't want to block the operation of the app waiting for a connection.
Bob
|
|
|
|
|
Bob Pawley wrote: I am looking at a socket connection as I don't want to block the operation of the app waiting for a connection.
A socket connection has nothing to do here. If you don't want to block the operation of the application, you need to run the processing on a background thread.
Bob Pawley wrote: I've searched copiously, but all examples I have found are for standalone socket connections.
Could someone point me to an example app that includes a socket connection to recieve infomation.
What do you meant by standalone socket connection? This[^] article is a good read on the subject.
Best wishes,
Navaneeth
|
|
|
|
|
* I have no knowledge of Delphi.
If the Delphi app is on the same machine as the C# app, you should use named pipes.
Named pipes is a method communication between processes without claiming a network socket.
Claiming a network socket when it is unnecessary is bad practice for it might block access for other applications.
Named pipes in C# @ MSDN[^]
|
|
|
|
|
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("wellcome to");
Console.Write(" " + args[0]);
Console.WriteLine(" " + args[1]);
|
|
|
|
|
And what's your question? BTW - it's bad practice to use arguments without testing to see if they are null, or if you've gone past the end of the array. There are these nasty things called Exceptions which end up taking you outside and whacking you with baseball bats.
|
|
|
|
|
If you want to keep the compiler happy you should watch the balance of symbols that come in pairs, such as { and }.
And if you want help around here, you'd better read the "how to get an answer" message on this page. Showing exact symptoms (compiler errors, run-time exceptions,...) is essential. Putting code snippets in PRE tags is highly recommended too.
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.
|
|
|
|
|
Pete and Luc both raise valid points.
How to fix them:
1) When you post a code fragment, use the "code block" widget to put <pre> and </pre> tags around it: this preserves the indentation and formatting and makes it a lot easier to read!
2) As Luc said, you do need to balance all "matched pairs": every '(' must have it's ')', every '{' must have it's '}', and so on:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("wellcome to");
Console.Write(" " + args[0]);
Console.WriteLine(" " + args[1]);
}
}
} Your program should now compile cleanly.
3) You also need (as Pete said) to check your inputs: what if you didn't provide any command line parameters?
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
if (args.Length >= 2)
{
Console.Write("wellcome to");
Console.Write(" " + args[0]);
Console.WriteLine(" " + args[1]);
}
else
{
Console.WriteLine("Usage: ConsoleApplication1 YourName");
}
}
}
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Hi All,
Does anyone know how to move/copy an email from one folder to another in C#?
Thank you,
Melanie
|
|
|
|
|
In Outlook? In Exchange? In Thunderbird?
|
|
|
|
|
Thank you for your quick reply, sorry about the lack of info.
It's an Exchange email account that I'm processing emails from using SmtPop.
http://csharpopensource.com/smtpopdotnet.aspx[^]
However, certain emails I'm wanting to copy to a seperate folder.
Thanks,
Mel
|
|
|
|
|
Mel, you can accomplish this using the Exchange Web Services. The method you want is MoveItem[^].
|
|
|
|
|
Pete,
Great, thank you I'll give that a go and let you know how it goes.
Mel
|
|
|
|
|
Excellent. Good luck.
|
|
|
|
|
Just a quick question can Exchange Web Services be used in windows applications as well as web apps?
Also, do you have an example of how to use the CopyItem method?
Thank you,
Mel
|
|
|
|
|
Dear programmers have a question, I have the contents of the database are displayed on the listview. Suppose we have a row numbers 1,2,3,4,5. after the removal of such line number 2, line numbers will be 1,3,4,5. How to do that after deleting a row will automatically renumber as 1,2,3,4. Thanks in advance
|
|
|
|
|
If they are coming from a database directly into the listview, there is a very good chance that the nunbers are the record ID in the database, and an even better chance that they are autonumber - i.e. the database assigns them, incrementing as it goes, and you do not have to worry about duplicates, because the database will not allow that.
If so, then do not attempt to change them: in the real world changing a record ID is not a good thing to do, and it can cause enormous problems, even if the database would let you - which for autonumber fields it won't.
Hide the column instead, if it offends you!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
I think this is a very correct answer to this question. The same question was posted in the Questions & Answers sections too..
|
|
|
|
|
Hi,
I am trying to do an app which has children windows inside it, and make it capable of when drag the mouse off the parent window it undocks and float all around the desktop, but for some reason i can seem to accomplish this. I am using the SetWindowLong method to change style of the window from WS_CHILD to WS_POPUP but it doesn't work, can someone please show me some code to make it work
long lastStyle = NativeMethods.GetWindowLong(myControl.Handle,
(int)NativeMethods.GetWindowLongConst.GWL_EXSTYLE);
long newStyle = NativeMethods.SetWindowLong(myControl.Handle,
(int)NativeMethods.GetWindowLongConst.GWL_STYLE,
(uint)NativeMethods.WindowStyles.WS_POPUP);
newStyle = NativeMethods.SetWindowLong(myControl.Handle,
(int)NativeMethods.GetWindowLongConst.GWL_EXSTYLE,
(long)(NativeMethods.WindowStylesEx.WS_EX_APPWINDOW | NativeMethods.WindowStylesEx.WS_EX_TOOLWINDOW));
myControl.Location = new Point(100, 200);
|
|
|
|
|
I would like to search through the buttons of a window handle and search for a specific button and if it exists perform an action, is there a way to do this?
If not, how can I identify a button and simulate a click based on the following info?
Thanks for reading!
>>>> Window <<<<
Title: HP OpenView ServiceCenter - Main Menu: HP OpenView ServiceCenter Client
Class: SWT_Window0
Position: 0, 90
Size: 1680, 960
Style: 0x96CF0000
ExStyle: 0x00100100
Handle: 0x005E24D6
>>>> Control <<<<
Class: SWT_Window0
Instance: 73
ClassnameNN: SWT_Window073
Name:
Advanced (Class): [CLASS:SWT_Window0; INSTANCE:73]
ID: 5510298
Text:
Position: 582, 407
Size: 57, 49
ControlClick Coords: 42, 30
Style: 0x56010000
ExStyle: 0x00100000
Handle: 0x0054149A
>>>> Mouse <<<<
Position: 632, 575
Cursor ID: 0
Color: 0x1272FA
>>>> StatusBar <<<<
>>>> ToolsBar <<<<
>>>> Visible Text <<<<
Top
Utilities
Maintenance
>>>> Hidden Text <<<<
|
|
|
|
|
If its a real native Win32 button, you can use FindWindow or FindWindowEx to find the window and send a BM_CLICK or WM_COMMAND message with SendMessage. If its not a native button (i.e. a WPF app, etc.), you can't do that and your only option is to simulate a mouse click with the mouse_event API.
|
|
|
|
|
Hi,
Thank you for the reply, do you have any code examples for this, I'm having a hard time finding anything online that looks like it will work with what I am doing. Or that will work with the window information I posted in my initial post. I do not believe it is a real native Win32 button.
|
|
|
|
|
Well, I don't have the HP openview software, so I couldn't tell you for sure. I don't know what tool your initial output is from, so try use Spy++ (comes with Visual Studio) instead. Use the binocular tool (6th button) then drag the cross hair thingy onto the title bar of the window and hit ok. NOTE: you need to start the HP app first, the refresh in the new Spy++ doesn't always work. Anyways... after you hit ok, you'll go to the window tree. You can expand the tree and see what controls are there. If the button is listed, its a native control. You might need to drill down in the tree to find it. Or you can just drag the cross hair directly onto the button.
If its not a native button, or even something like a toolbar its trickier... but it seems like from your output you can find the button of interest and get its screen rectangle. So then just use mouse_event() http://msdn.microsoft.com/en-us/library/ms646260(v=vs.85).aspx to simulate left button down | left button up at the absolute screen coordinates.
|
|
|
|
|
Hi,
Thanks again for the reply.
The cross hairs option gave me this, it looks like the button stays in the same general area no matter the window size, but its Class Name is not usable (all buttons are named that) and it does not seem to have any other uniquely identifiable information about it?
Is my best option the coordinates based mouse click?
Properties for window 0x00592342
Item Value
Class Name SWT_Window0
Text
Rectangle 576, 545, 633, 594
Size 57, 49
Client Rectangle 0, 0, 57, 49
Client Size 57, 49
Styles WS_CHILD
WS_VISIBLE
WS_CLIPSIBLINGS
WS_CLIPCHILDREN
WS_TABSTOP
StylesEx WS_EX_LEFT
WS_EX_LTRREADING
WS_EX_RIGHTSCROLLBAR
WS_EX_NOINHERITLAYOUT
ID 5841730
Properties Atom: #43288 0xFFFFFFFF (-1)
Class specific Window is Ansi
Owner EXE C:\Program Files\Peregrine Systems\ServiceCenter 6.2\Client\jre\bin\javaw.exe
|
|
|
|
|