473,395 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Readonly propert of a Textbox

How do I override a Readonly property of a textbox control in a custom
Textbox control?
Sep 3 '08 #1
4 2085
It isn't virtual, so you can't. What do you need to do?

Marc
Sep 3 '08 #2
I have created a custom Textbox control. When this control is placed on a
form; the ReadOnly property is not available.
I have implemented some properties, code below, but don't know exactly how
to implement Readonly property:
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace MyControls
{

public partial class MyTextBox : UserControl
{
public string currentText;
public delegate void TextChangedHandler(object MyTextBox,EventArgs e);
public event TextChangedHandler OnTextChange;
public MyTextBox()
{
InitializeComponent();
baseTextBox.Text = "";

}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);

}
protected override void OnLostFocus(EventArgs e)
{
base.OnLostFocus(e);

}

"Marc Gravell" wrote:
It isn't virtual, so you can't. What do you need to do?

Marc
Sep 3 '08 #3
On Sep 3, 11:16*am, Ryan <R...@discussions.microsoft.comwrote:
I have created a custom Textbox control. When this control is placed on a
form; the ReadOnly property is not available.
I have implemented some properties, code below, but don't know exactly how
to implement Readonly property:

using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace MyControls
{

* * public partial class MyTextBox : UserControl
* * {
* * * * public string currentText;
* * * * public delegate void TextChangedHandler(object MyTextBox,EventArgs e);
* * * * public event TextChangedHandler OnTextChange;
* * * * public MyTextBox()
* * * * {
* * * * * * InitializeComponent();
* * * * * * baseTextBox.Text = "";

* * * * }
* * * * protected override void OnGotFocus(EventArgs e)
* * * * {
* * * * * * * * base.OnGotFocus(e);

* * * * }
* * * * protected override void OnLostFocus(EventArgs e)
* * * * {
* * * * * * * * base.OnLostFocus(e);

* * * * }

"Marc Gravell" wrote:
It isn't virtual, so you can't. What do you need to do?
Marc- Hide quoted text -

- Show quoted text -
And how your control is a textbox? You are deriving from UserControl,
no Textbox
Sep 3 '08 #4
By the "baseTestBox", it rather looks like you have *encapsulated* a
TextBox - i.e. you have a UserControl that *contains* a TextBox. In
which case, just add a pass-thru ReadOnly property:

public bool ReadOnly
{
get {return baseTextBox.ReadOnly;}
set {baseTextBox.ReadOnly = value;}
}

For info, the overrides you have added don't do anything, so should be
removed. There is no need to declare a custom delegate - this
signature is the same as EventHandler, which is expected by several
binding frameworks. The event could again be a pass-thru, except this
would obscure the sender. For info, the event should be called
TextChanged if you want binding notifications to work.

But I suspect you might get more joy by simply inheriting from
TextBox.

Marc
Sep 3 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: pv_kannan | last post by:
Hello, I am stuck with a problem trying to mimic the behavior of a Windows Forms Readonly textbox in HMTL/ASP.NET. Basically, I would like the text to be readonly and overflow the textbox...
10
by: GP | last post by:
Is it possible to iterate through all the controls collection and make the textboxes alone as read only.I don't see a readonly property for the Control.Can some one help me in this context? I...
3
by: Lyners | last post by:
I am having a hard time with this one, and I thought it would be easy. I have a datagrid in which I have textboxs for users to enter data. One of the fields in the database behind the datagrid...
2
by: Marcin Floryan | last post by:
I am creating a custom control (Inherits UserControl) and my control containt a TextBox control. TextBox control has a Property called "ReadOnly". I would like to expose this property outside my...
4
by: Doug Bell | last post by:
Hi, I needed to make a TextBox on a DataGrid ReadOnly based on the condition of another cell on its row. I achieved this using a Custom Data Column Class "DacDGTextColLotNo" but I can't get the...
9
by: ShaneFowlkes | last post by:
Hey guys... I have a form that asks for several dates. I tried using asp calendar controls to set values of the date textboxes which were readonly. I found this annoying since each time I...
1
by: Thierry | last post by:
Hi, We are currently upgrading our .Net web apps from framework 1.1 to 2.0 Everything is going quite smoothly except a bug with textbox value not rendered when having propery readonly=true on the...
4
by: H-S | last post by:
Please help. This is a real puzzler! Originally posted on microsoft.public.dotnet.framework.windowsforms but no answer found! I have a read-only textBox which shows the results of a selection...
2
by: johnlim20088 | last post by:
Hi Someone please help me string typ; if (e.Row.RowType == DataControlRowType.DataRow) { typ = e.Row.Cells.Text;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.