 |
| Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 3rd, 2004, 11:08 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
esche:
locked porperty on .net just lock the control to the form, making you not enable to move it...
the locked from vb6 was change to readonly...
HTH
Gonzalo
|
|

February 14th, 2006, 10:26 PM
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry to bring this thread back up and it came out from my google search to set textbox as readonly but no grey out the textbox.
I found a simple solution:
1) Set the textbox readonly property to false
2) on event keypress, I'll handle this event
Code:
Private Sub MyReadOnlyTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyReadOnlyTextBox.KeyPress
e.Handled = True
End Sub
This will not allow user to enter or delete anything in the textbox and you can set whatever color you like, as well as allowing user to select text and set focus to the textbox.
|
|

June 2nd, 2006, 12:27 PM
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Probably old news but for the googlers...
setting Enabled=No, Locked=Yes, Tab Stop=No might be another option.
|
|

November 15th, 2006, 06:29 PM
|
|
Registered User
|
|
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Why wouldnt you just use a label
Nick Cammarata
|
|

March 13th, 2007, 12:16 PM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You might want to try something like this:
I have created myTextBox with an override for the paint. If the control is disabled - its one color and enabled - another. You can check on the box to see if it is disabled by the mouseover override. The project consists of 2 controls tbHowdy and btnEnable. In the Form1.Designer I replaced the default Initialize component with:
this.tbHowdy = new disable_textbox.Form1.myTextBox();
Hope this helps
namespace disable_textbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnEnable_Click(object sender, EventArgs e)
{
if (tbHowdy.Enabled)
{
tbHowdy.Enabled = false;
btnEnable.Text = "Enable";
}
else
{
tbHowdy.Enabled = true;
btnEnable.Text = "Disable";
}
}
public class myTextBox : TextBox
{
public myTextBox()
{
SetStyle(ControlStyles.UserPaint, true);
}
// override on paint
protected override void OnPaint(PaintEventArgs e)
{
if (this.Enabled)
{
SolidBrush drawBrush = new SolidBrush(Color.Red); //Use the ForeColor property
// Draw string to screen.
e.Graphics.DrawString(Text, Font, drawBrush, 0f, 0f); //Use the Font property
}
else
{
SolidBrush drawBrush = new SolidBrush(Color.Blue); //Use the ForeColor property
// Draw string to screen.
e.Graphics.DrawString(Text, Font, drawBrush, 0f, 0f); //Use the Font property
}
}
protected override void OnMouseHover(EventArgs e)
{
base.OnMouseHover(e);
base.Text = "blah";
}
}
}
}
|
|

March 13th, 2007, 12:21 PM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry - I see this is a VB forum - but I am sure that it is similar in VB
|
|

July 12th, 2007, 10:19 AM
|
|
Registered User
|
|
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
When I refresh the control, it goes to enabled again and when highlighted the font changes, disappears, etc... how do I return the entire textbox as normal again.
Quote:
quote:Originally posted by zamnut6
You might want to try something like this:
I have created myTextBox with an override for the paint. If the control is disabled - its one color and enabled - another. You can check on the box to see if it is disabled by the mouseover override. The project consists of 2 controls tbHowdy and btnEnable. In the Form1.Designer I replaced the default Initialize component with:
this.tbHowdy = new disable_textbox.Form1.myTextBox();
Hope this helps
namespace disable_textbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnEnable_Click(object sender, EventArgs e)
{
if (tbHowdy.Enabled)
{
tbHowdy.Enabled = false;
btnEnable.Text = "Enable";
}
else
{
tbHowdy.Enabled = true;
btnEnable.Text = "Disable";
}
}
public class myTextBox : TextBox
{
public myTextBox()
{
SetStyle(ControlStyles.UserPaint, true);
}
// override on paint
protected override void OnPaint(PaintEventArgs e)
{
if (this.Enabled)
{
SolidBrush drawBrush = new SolidBrush(Color.Red); //Use the ForeColor property
// Draw string to screen.
e.Graphics.DrawString(Text, Font, drawBrush, 0f, 0f); //Use the Font property
}
else
{
SolidBrush drawBrush = new SolidBrush(Color.Blue); //Use the ForeColor property
// Draw string to screen.
e.Graphics.DrawString(Text, Font, drawBrush, 0f, 0f); //Use the Font property
}
}
protected override void OnMouseHover(EventArgs e)
{
base.OnMouseHover(e);
base.Text = "blah";
}
}
}
}
|
|
|

July 17th, 2008, 09:57 AM
|
|
Registered User
|
|
Join Date: Jul 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
quote:Originally posted by cammarata123
Why wouldnt you just use a label
|
My reasoning would be I want the text to be allowed to be copied to the clipboard. Eating all keypress events, doesn't give me that either.
But allowing Ctrl-C through gives me what I want.
If Not (Control.ModifierKeys = Keys.Control AndAlso e.KeyChar = "c"c) Then
e.Handled = True
End If
|
|

July 17th, 2008, 10:24 AM
|
|
Registered User
|
|
Join Date: Jul 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry, that code didn't actually work, but this seems to do the trick.
' don't handle Ctrl-C
If Not (e.KeyChar = Chr(3)) Then
e.Handled = True
End If
|
|
 |