 |
|
 |
Poorly coded, very repetitive code for the 4 textboxes for each ip segment & doesn't support pressing period if the 1st ip segment is filled and selected in full to goto the next segment.
|
|
|
|
 |
|
 |
Nice job.Thank you for sharing.
|
|
|
|
 |
|
 |
How can iuse it in web forms?
|
|
|
|
 |
|
|
 |
|
 |
Im wondering if mawnkay can be reached somehow?
I have managed to compile some code from the threads posted in this forum, combined with my own and mawnkay's of course to make an exact duplicate of the current windows ip text box found in the tcp/ip settings, im wondering how i can release this without infringing anyone .. text validation/space bar key press etc etc is all done also.
will appreciate if someone can take a look at it, and also maybe modify it to make the code look cleaner! thanks.
|
|
|
|
 |
|
 |
HI,
Would like to know whether the IP Textbox control is open source
Are there any licencing agreements associated with this
It indeed serves my purpose and am keen on using it
Regards
Raji Ramachandran
|
|
|
|
 |
|
 |
Hey,
although this IP Textbox has saved a LOT of work for me, i wonder.... how do you check the IP Textbox for filled in ip addresses?
I'm using a check + messagebox in a form and somehow if I empty the IP Textbox with String.Empty and then check if its really empty, it still thinks there are numbers filled inside the textbox.
Does anyone have a solution for a novice like me?
|
|
|
|
 |
|
|
 |
|
 |
It seems that the Text property cannot be successfully databound (even after adding the Bindable attribute). It seems to have something to do with the override of Text.
Giving the Text property a different name instantly makes databinding possible.
Just rename and add
[System.ComponentModel.Bindable(true)]
above it (and Browsable(true) if you want it in the designer).
Joel
|
|
|
|
 |
|
 |
When pressing the left or right arrow keys you should be able to move from one cell to the next. Also it would be nice to have a bool option as to whether or not a user wishes to type all the way through like (123123123) without pressing a tab key, mouse click, or arrow key.
Otherwise the control look really good.
|
|
|
|
 |
|
 |
Look at the Little Changes comment. He implemented exactly what I thought it needed when I looked at it.
The other change that I implemented was adding an ErrorProvider to replace the MessageBox. I set it on error, and clear on every KeyPress and KeyDown.
---
(modification)
I spoke too soon. I also added verification on the leave event to either clear or set the ErrorProvider.
Joel
-- modified at 9:36 Thursday 1st December, 2005
|
|
|
|
 |
|
 |
How to set the focus ?
IPTextBox ipTextBox;
...
ipTextBox.Focus();
Don't work ???
|
|
|
|
 |
|
 |
err, I don't have it in front of me right now, but I never overrode the Focus() method for the control. You could probably add something like this:
public void override Focus()
{
box1.Focus();
}
Something like this should probably work, I'll check it out when I get a chance.
|
|
|
|
 |
|
 |
Okay, just worked on it for a bit today and it seems that you cannot override Focus(). But the standard
this.ipTextBox1.Focus();
seems to work just fine.
|
|
|
|
 |
|
 |
I want to say you did a gr8 job with this control. I only modified 2 little things before including it in my custom control library.
You need to add this to allow navigation between the textboxes with the arrow keys on the keyboard
private void Box1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
this.Box2.Focus();
}
private void Box2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
this.Box3.Focus();
if (e.KeyCode == Keys.Left)
this.Box1.Focus();
}
private void Box3_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Right)
this.Box4.Focus();
if (e.KeyCode == Keys.Left)
this.Box2.Focus();
}
private void Box4_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
this.Box3.Focus();
}
And I added the Browsable attribute to the Text property to make it available on the property grid
[Browsable(true)]
public override string Text
|
|
|
|
 |
|
 |
Good ideas, didn't know how to do the property grid thing so thanks for the help there, and there's only a small issue with the arrow keys. If there are already digits in the boxes, you wouldn't be able to move the cursor from one digit to the next using this code. This is a good start, but a perfect solution might be a little more complicated.
|
|
|
|
 |
|
 |
This ditty of extra code using SelectionStart, TextLength, and SelectionLength should let you arrow through your code and text boxes - just place this where you want it, and it only iterates to the next box whenever your at the beginning of your text or end of entered text:
if (e.KeyCode == Keys.Right && (Box2.SelectionStart == Box2.TextLength))
this.Box3.Focus();
else if (e.KeyCode == Keys.Left && (Box2.SelectionStart == Box2.SelectionLength))
this.Box1.Focus();
|
|
|
|
 |
|
 |
1. put up pictures
2. you can wrap the standard IP Address control w/ much less code (this is a quick & dirty wrapper. I have a much better implementation, but this is just from memory):
namespace NullFX.Controls {
using System;
using System.Net;
using System.Windows.Forms;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
public struct Nmhdr {
public IntPtr HWndFrom;
public int IdFrom;
public int Code;
}
[StructLayout(LayoutKind.Sequential)]
public struct NmIPAddress {
public Nmhdr Hdr;
public int Field;
public int Value;
}
public enum IPField {OctetOne = 0,OctetTwo=1,OctetThree=2,OctetFour=3}
public delegate void TextChangedHandler(object sender, TextChangedEventArgs e);
public class TextChangedEventArgs : EventArgs {
private int _field, _value;
public int Field {
get{return _field;}
}
public int Value {
get{return _value;}
}
public TextChangedEventArgs(int field, int value):base() {
_field = field;
_value = value;
}
}
public class IPAddressControl : TextBox {
private const int WM_NOTIFY = 0x004E,
WM_USER = 0x0400,
WM_REFLECT = WM_USER + 0x1C00,
IPM_SETRANGE = (WM_USER+103),
IPM_GETADDRESS = (WM_USER+102),
IPM_SETADDRESS = (WM_USER+101),
IPM_CLEARADDRESS = (WM_USER+100),
IPM_ISBLANK = (WM_USER+105);
private int[] values = new int[4];
new public event TextChangedHandler TextChanged;
public IPAddressControl() : base() {
for(int i = 0; i < 4; i++)
values[i] = 0;
}
protected virtual void OnTextChanged(TextChangedEventArgs e) {
if(TextChanged != null) TextChanged(this, e);
}
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ClassName = "SysIPAddress32";
cp.Height = 23;
return cp;
}
}
public bool SetIPRange(IPField field, byte lowValue, byte highValue) {
Message m = Message.Create(Handle, IPM_SETRANGE, (IntPtr)((int)field) , MakeRange(lowValue, highValue));
WndProc(ref m);
return m.Result.ToInt32() > 0;
}
public System.Net.IPAddress IPAddress {
get{
return IPAddress.Parse(base.Text);
}
}
public bool IsBlank {
get{
Message m = Message.Create(Handle, IPM_ISBLANK, IntPtr.Zero, IntPtr.Zero);
WndProc(ref m);
return m.Result.ToInt32() > 0;
}
}
new public void Clear() {
Message m = Message.Create(Handle, IPM_CLEARADDRESS, IntPtr.Zero, IntPtr.Zero);
WndProc(ref m);
}
private System.Net.IPAddress GetIpAddress(IntPtr ip) {
return new IPAddress(ip.ToInt64());
}
private IntPtr MakeRange(byte low, byte high) {
return (IntPtr)((int)((high << 8) + low));
}
protected override void WndProc(ref Message m) {
if(m.Msg == (WM_REFLECT + WM_NOTIFY)) {
NmIPAddress ipInfo = (NmIPAddress)Marshal.PtrToStructure(m.LParam, typeof(NmIPAddress));
if(ipInfo.Hdr.Code == -860) {
if(values[ipInfo.Field] != ipInfo.Value) {
values[ipInfo.Field] = ipInfo.Value;
OnTextChanged(new TextChangedEventArgs(ipInfo.Field, ipInfo.Value));
}
}
}
base.WndProc (ref m);
}
}
}
/bb|[^b]{2}/
|
|
|
|
 |
|
 |
If the code you posted is
MadHatter ¢ wrote:
just from memory
then your memory is exceptionally good!!
|
|
|
|
 |
|
 |
well, there's a bug in the original SysIPAddress control that messes up fonts when you build in designer mode (it destroys the parent's font as well), so the code to compensate for that, as well as some uitype editors, designers and other usefull properties are missing.
/bb|[^b]{2}/
|
|
|
|
 |
|
 |
MadHatter ¢ wrote:
you can wrap the standard IP Address control w/ much less code (this is a quick & dirty wrapper. I have a much better implementation, but this is just from memory):
Just wondering if you could throw up a link or something to your stuff. I was still kinda new to C# when I wrote this stuff so I don't doubt there's better ways and I'd like to check out what you got.
|
|
|
|
 |
|
 |
Sure. I'll put something together and post it on my site (& link to it here).
/bb|[^b]{2}/
|
|
|
|
 |