|
Hi
If You are new to C# it wont be easy.
First of all You can not use buttons, because when You click a button that button will steal focus, so your key stroke will have no notion where to go.
The only (winforms)control that not steals focus is a label, but a label has not got the right properties to act as a key.
The solution is to create a custom control derived from label control.
to do so You must add this class to your project:
namespace YOURPROJECTNAMESPACE
{
public sealed class MyControl : Label
{
public MyControl()
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
BackColor = Color.Transparent;
}
public Image ControlImage { get; set; }
protected override void OnPaint(PaintEventArgs e)
{
if (ControlImage != null)
{
e.Graphics.DrawImage(ControlImage, 4, 4, Width - 8, Height - 8);
}
var rectangle = new RectangleF(2, 0, Width, Height + 5);
var format = new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
};
e.Graphics.DrawString(Text, Font, Brushes.Black, rectangle, format);
}
}
}
After you have done this You will find in the designer toolbox MyControl.
Then drag a flowLayouPanel from the toolbox. Populate this panel by dragging as many MyControls as you need. in properties give them a nice picture of a key and a character as text.
One more thing to do, In the designer doubleclick each key,and in the click event this:
private void myControl1_Click(object sender, EventArgs e)
{
SendKeys.Send("{1}");
}
private void myControlEnter_Click(object sender, EventArgs e)
{
SendKeys.Send("{ENTER}");
}
Etc.
If You have any more questions just ask,
Groover
0200 A9 23
0202 8D 01 80
0205 00
modified 13-Nov-15 21:47pm.
|
|
|
|
|
Well, it can be easy: all you need to do to keep the Focus on the TextBox Control when a Button is clicked is to set the TextBox 'Capture to 'true in the Click EventHandler.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
hello people i have studied a network sniffer on this site <a href="http://www.codeproject.com/Articles/17031/A-Network-Sniffer-in-C"> </a>[<a href="http://www.codeproject.com/Articles/17031/A-Network-Sniffer-in-C" target="_blank" title="New Window">^</a>] so how can i do the reverse which is creating the packet in c# or vb.net pcap seems not to work
thank you
|
|
|
|
|
1. I suggest you post on the article itself
2. You may have pasted the link wrongly, since we can't click it
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
Crafting packets from scratch can only be done by administrators. I you're trying to do this as a normal user, it's never going to work. Why? Security reasons.
|
|
|
|
|
i working on a NAT project of mine .i can receive packtes and get the info such as source ip and dest ip but i need to do the reverse by creating a packet and im an administartor by the way
|
|
|
|
|
|
I have object with members of different types like this:
public class Node
{
public int itemID = -1;
public int counter = 1;
public Node parent = null;
public List<Node> childs = new List<Node>();
public Node nodeLink = null;
}
And I have class tree
public class tree
{
public List<int> headerList = null;
public Dictionary<int, Node> mapItemNodes = new Dictionary<int, Node>();
public Dictionary<int, Node> mapItemLastNode = new Dictionary<int, Node>();
public Node root = new Node();
}
And I need your help to serialize and deserialize an object of the class tree
|
|
|
|
|
Rather than using fields, you're going to have to use properties if you want to use a default serializer - and don't forget the Serializable attribute on your class.
|
|
|
|
|
Note: I have two classes where I use XmlSerializer, and they have fields -which are correctly serialized.
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
So long as the fields are public, yes that will work. If there are fields that are private, they must be wrapped in public properties in order to work.
|
|
|
|
|
did your classes contain dictionaries? or would you please give me an example
modified 12-Nov-15 9:14am.
|
|
|
|
|
|
Your class "tree" contains Dictionaries - and that causes a problem: it won't be serializable by the XMLSerializer. That means: you havt to write your own serialization / deserialization code.
|
|
|
|
|
fyi: I have written a Tree structure very much like this, and had no problem serializing/de-serializing Dictionaries using WCF.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
You can use WCF (DataContract and DataMember) to serialize structures like this; in fact, I've written a very similar tree-structure, with internal Dictionaries, and it serializes/de-serializes okay. Compressing the XML output of the WCF serializer with GZip results in file sizes often less than 50% of the umcompressed file, and often with file sizes as low as 25% of the uncompressed XML. Those file sizes are comparable to the size of the structure(s) saved with binary serialization.
I gave an example of using WCF on a recent answer to a QA question here: ^].
Do read the documentation on using WCF; and study the various fields of the DataContract and DataMember Attributes that are optional; they are very useful !
Also, note that if your Class inherits from some Generic Collection, like this:
[DataMember]
public class MyClass : List<SomeOtherClass>
{
[DataMember]
public int SomeIntProp { get; set; }
} This will not serialize, even if 'SomeOtherClass is also properly adorned with WCF Attributes. I've never found an explanation of this.
So, code the generic Collection as a Property in another Class.
Suggestion: use Properties, not Fields.
Another idea: Here you'll find an implementation of a Generic approach to using WCF ... the code was inspired by the comments and ideas of Pete O'Hanlon on that thread, but if the code doesn't work for you, that's my fault
[^]
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
modified 12-Nov-15 17:15pm.
|
|
|
|
|
Dear all,
thanks a lot for your replies, but actually I am confused because I am a new user to c#, and now I am using ConsoleApplication in my application. my aim from asking you is to write the content of the tree to a file and retreiving it a gain to the same object regardless the used method. I hope that you help me in my problem.
|
|
|
|
|
Hi,
I have a little method which registeres an extension (edit: like .ext) into the Windows registry. Does anyone have an idea how I can tell Windows to open a file with the respective extension only in a new program instance, if currently none is running? If the program is already running, a new tab in my program should be created (I have a event void opentab(object sender, EventArgs e) to open a new tab). But how can I tell windows not to open a new instance but to call the running program and let it run the event?
I think one can somehow do it with a subnode "ddeexec" in the subnode "open", but I'm not sure and it didn't work for me.
Best wishes
robin
void DefineAssociations(string extension, string IconFile)
{
string keyName = extension;
RegistryKey key = Registry.ClassesRoot.OpenSubKey(keyName);
if (key != null)
{
string apppath = "";
apppath = Application.ExecutablePath.ToLower() + " \"%1\"";
key.SetValue("", "MyProg");
RegistryKey iconkey;
iconkey = key.CreateSubKey("DefaultIcon");
iconkey.SetValue("", Environment.CurrentDirectory + "\\resources\\" + IconFile);
key = key.CreateSubKey("shell");
key = key.CreateSubKey("open");
key = key.CreateSubKey("command");
key.SetValue("", apppath);
}
}
|
|
|
|
|
I don't think it's possible. Anyway, long story short - that's not the way to do it.
It's your job to find out if another instance is running, and if so, to notify it. It's not an easy task though. There's quite a bit of code required to do this. Namely, first find out if another instance of your app is running, and if so, you need to notify it and send it the new file to open.
More or less, something like this:
[StructLayout(LayoutKind.Sequential)]
public struct COPYDATASTRUCT {
public IntPtr dwData;
public int cbData;
[MarshalAs(UnmanagedType.LPStr)] public string lpData;
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
public const int WM_COPYDATA = 0x004A;
...
var running_already = Process.GetProcessesByName("Yourapp").ToDictionary(x => x.Id, x => x);
running_already.Remove(Process.GetCurrentProcess().Id);
if (running_already.Count > 0) {
if (args.Length == 0)
return;
string open = args[0];
var cds = new win32.COPYDATASTRUCT {
dwData = new IntPtr(0),
cbData = open.Length * 2 + 1,
lpData = open
};
var handle = running_already.First().Value.MainWindowHandle;
win32.SendMessage(handle, win32.WM_COPYDATA, IntPtr.Zero, ref cds);
return;
}
protected override void WndProc(ref Message m) {
if (m.Msg == win32.WM_COPYDATA) {
var st = (win32.COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof (win32.COPYDATASTRUCT));
string open = st.lpData;
util.postpone(() => on_file_drop(open), 100);
}
base.WndProc(ref m);
}
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
Wow, it works up to the point at which I just need to call the file open event. Great! thanks a lot;)
robin
|
|
|
|
|
Glad it works I copied the code from my app - it took me a while to do it right
Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
It's impossible; here's the code to do the impossible -
+5
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
|
|
|
|
|
That step is to be cared of by your program opening the file, not by the registry. The concept is called "single instance application".
|
|
|
|
|
I want to develop Windows App for NGO similar to below URL https://play.google.com/store/apps/details?id=com.savethelife.csr
This is for Non profitable Organisation, so cost should be lower side.Please suggest free database websites those can provide free data services? Thank
|
|
|
|