|
This is against OOP principals. All properties etc of the base object shold be present in the deriving object.
However, Microsoft do this themselves all the time! The PictureBox is a good example. It has no browsable Text property in the property grid or in the code editor via intellisense, but it's still there as it derives from System.Windows.Forms.Control which has the Text property.
The way to achieve this is to do something like this with properties, events and methods that you don't want to be visible.
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
public class MyPictureBox : PictureBox
{
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This property is obselete", true)]
public new Color BackColor
{
get { return base.BackColor; }
set { base.BackColor = value; }
}
} This will make the BackColor property 'disappear' IF MyPictureBox is in a seperate assembly. It will not work if in the same assembly, or added as a project reference to another project - it must be a reference to a seperate dll.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks for your great help.
I just wanna ask if you could help me with this in VB.NET !
it is a long time I am not working in C and I could not match your example to a VB code.
Cheers,
|
|
|
|
|
I don't really do VB - I think this is correct. I don't have VB installed on this machine so it's from memory only and untested!
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.System.Windows.Forms
Public Class MyPictureBox
Inherits PictureBox
<Browsable(False)> _
<EditorBrowsable(EditorBrowsableState.Never)> _
<Obsolete("This property is obselete", true)> _
Public Property BackColor() As Color
Get
Return MyBase.BackColor
End Get
Set(ByVal value As Color)
MyBase.BackColor = value
End Set
End Property
End Class
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
This is the VB code I have here, there are many properties inherited from Picturebox to this class. how can i make all of inherited properties nob-browsable!? in my test app I have an instance of this class assigned to a PropertyGrid (as selectedobject) and it is showing all of them!?!?!?
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class A
Inherits Windows.Forms.PictureBox
Private _A1 As Integer
Private _A2 As Integer
Private _A3 As Integer
<CategoryAttribute("Test"), Browsable(True)> Public Property A1() As Integer
Get
Return _A1
End Get
Set(ByVal value As Integer)
_A1 = value
End Set
End Property
<CategoryAttribute("Sample"), Browsable(True)> Public Property A2() As Integer
Get
Return _A2
End Get
Set(ByVal value As Integer)
_A2 = value
End Set
End Property
<CategoryAttribute("Sample"), Browsable(True)> Public Property A3() As Integer
Get
Return _A3
End Get
Set(ByVal value As Integer)
_A3 = value
End Set
End Property
End Class
|
|
|
|
|
You will need to apply the same attributes that I posted above to EVERY property etc that you want to hide. There is no shortcut I'm afraid. The System.Windows.Forms.Control class is where most of the stuff you're seeing that you don't want comes from. That in turn derives from all of these:
Component, IDropTarget, ISynchronizeInvoke, IWin32Window, IBindableComponent, IComponent, IDisposable
If you derive from Component instead, you don't get any of the other stuff, but you then don't have a visible control. To make it visible as a control you'd need to implement IWin32Window [Edit] I think [/Edit]. I've no idea how to do that - I'm sure it is not trivial. If you decide to try, and figure it out, please write an article about it because I'd love to learn!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Monday, July 27, 2009 10:38 AM
|
|
|
|
|
Dave, your answer to this question was great...
I was just thinking about something to make this more useful..
if Class A inherits from Windows.Forms.PictureBox or whatever component and I need the Picturebox width and image to be used in my instances of A (MyA Object) how can i hide it?! I don't want to overload the inherited property. Also I couldn't use Shadowing!!!
how can i use some of inherited properties but hide them in propertyGrid...!?
Cheers,
|
|
|
|
|
If you remove the Obselete attribute, and in the getter/setter use the base values like I did, then you can continue to use the properties - they will just not be visible to the property grid or intellisense.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I tried it..! I really don't know how to use it
do you have any sample for ObsoleteAttribute? I googles it but no useful samples found
|
|
|
|
|
MSDN[^]
It's pretty simple really.
Browsable(false) hides the property form the grid.
EditorBrowsable(EditorBrowsableState.Never) hides the property from the code editor.
Obsolete("xxx") makes the compiler generate a warning if there is an attempt to use the property.
Obsolete("xxx", true) makes the compiler generate an error (stops compilation) if there is an attempt to use the property.
You can create a new property and use it to get/set a different property (hidden or base class etc). Here is a code example - again in C#, but if you compare the code I provided previously, you should be able to translate.
public class MyPictureBox : PictureBox
{
[Browsable(false),
EditorBrowsable(EditorBrowsableState.Never),
Obsolete("This property is obselete", true)]
public new int Width
{
get { return base.Width; }
set { base.Width = value; }
}
[Browsable(false),
EditorBrowsable(EditorBrowsableState.Never),
Obsolete("This property is obselete")]
public new int Height
{
get { return base.Height; }
set { base.Height = value; }
}
public int MyWidth
{
get { return base.Width; }
set { base.Width = value; }
}
public int MyHeight
{
get { return Height; }
set { Height = value; }
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
There is not any thing like "base" in VB
I reckon I have to start my application in C#, this bloody VB does not have the flexibility of C#. I have to migrate to C# and it is really hard....
|
|
|
|
|
Hamid Amrabadi wrote: There is not any thing like "base" in VB
Well, that might come as a surprise to the inventors of the language since they included the MyBase keyword to cover this.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
As Pete said, MyBase will do it.
Learning C# isn't so hard. Inspite of all the hype, VB.NET and C# are very similar, mostly just syntax differences as you can see by comparing my VB example previously with the C# one. Once you get used to it, you may wonder how you ever managed to cope with VB
If you want to try, just have a go!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Another option you might want to consider is writing a class that implements ICustomTypeDescriptor.
Normally, a property grid fetches a type descriptor that (no surprise here) describes the type. You can create custom descriptors that alter behaviors; change editors on the fly, hide properties, show additional 'pseudo' properties, etc...
ICustomTypeDescriptor is implemented by a few classes, you might want to check the MSDN pages for more info on how to use this, if you're clever it will be much easier than rewriting classes with New properties and different attributes.
|
|
|
|
|
I have a c# .net 2.0 application that I created. What I need to know is how do I create a true
".exe" embedable code. I have a gizmo that I want to program. I must confess that I am beyond
my realm with this but thats how we learn. I understand how the .net framework works and how it
passes the assemblys to the "JIT" and the JIT the converts it to true machine code that the processer executes. do other platforms like borland create true ".exe's"? Or do I need to learn
Assembly language? I hope not as I am getting good with C# It is pretty straight forward. Maybe there is a compiler that will do what I need.
Thanks in advance.
Regards
Rick Osburn
p.s.
I am famillar with windows ce but I dont want to mess with the licensing fees just want to burn
it into a Eprom.
|
|
|
|
|
You can post your questions only one time!!!
BTW, if you want to develop an embedded system, there are specific dedicated ide's available for the same! Qnx MOmentics, Carbide etc etc....
.Net codes are executed only through .net framework!@!! So creating a standalone exe is merely impossible with .net@!!!
And you need not learn assebly language, whereas you can program with c or c++ libraries which will be converted automatically to corresponding assembly codes by the compilers!
Have a Happy Coding.....
|
|
|
|
|
I have Dictionary that contain (key values)
I want to display it in Grid in WPF in one row only
I mean : make the key as Column name and the related value the field value
so how can i do that I think I need to Build Dynamic Class
by Reflection and convert the key value of the dictionary to Properties
after that initialize an object and fill its properties with values from
dictionary after that bind the object to the Grid .
is that right or is there any easier way ??
You have To Search About The Truth Of Your Life
Why Are you Here In Life ?
|
|
|
|
|
Hi,
I want to show a tooltip.
How to show a tooltip in Win Ce?
what a class and namespace is for it?
Or i must use a API function? what?
Thanks
|
|
|
|
|
Hi,
I did some tests and realized that multicast delegates are slower than a generic list of delegates.
Did i make a mistake or is this correct?
This is the code i used.
class MyObject {
const int childMax = 10;
const int runMax = 100000000;
Stopwatch SW = new Stopwatch();
event EventHandler MyEvent;
List<EventHandler> eventList = new List<EventHandler>();
Dictionary<string, EventHandler> eventDict = new Dictionary<string, EventHandler>();
int iterator = 0;
public MyObject() {
for (int i = 0; i< childMax ; i++ ) {
eventList.Add(MyFunc);
eventDict.Add(i.ToString(),MyFunc);
MyEvent += MyFunc;
}
}
public void Test() {
SW.Start();
for (int i = 0; i< runMax ; i++ ) {
MyEvent(null,null);
}
SW.Stop();
Console.WriteLine("Iterator=" + iterator.ToString("n") + " using Events, Elapsed: " + SW.Elapsed.ToString());
SW.Reset();
SW.Start();
for (int i = 0; i< runMax ; i++ ) {
for (int j = 0; j < childMax; j++) {
eventList[j](null,null);
}
}
SW.Stop();
Console.WriteLine("Iterator=" + iterator.ToString("n") + " using List, Elapsed: " + SW.Elapsed.ToString());
SW.Reset();
}
private void MyFunc(object sender, EventArgs e) {
iterator++;
}
}
This is the result on my machine (2,2 gHz)
Iterator=1.000.000.000,00 using Events, Elapsed: 00:00:06.2153030
Iterator=2.000.000.000,00 using List, Elapsed: 00:00:04.8695574
Press any key to continue . . .
|
|
|
|
|
Not much of an actual difference. Just bear it in mind and don't use an event when you don't need to.
"Use the right tool for the right job." -- Scotty, et al
|
|
|
|
|
Hi,
running same code on a slower CPU (Intel Atom N270) I get the opposite result:
100M iter: events=3.9s list=5.1s
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
That's 14ns, yes nano seconds, difference per iteration.
I can't think of a real world situation that I've come across where that would be significant. I've certainly never had 100 million subscribers to an event!
Performance differences like this often exist but results can vary dramatically depending on other parameters such as hardware etc, and normally it is of no consequence anyway.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Why Dave, there are over 6 million CPians reading your daily messages, plus an unknown number of anonymous people, aka non-members; you may not consider them subscribers but they are real. Don't put them down.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I know CP has that many members, but it's only you saying that, that I've suddenly realised millions of people may read what I post... scary! Quite a resposibility really
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello all,
I have this nagging error which i have applied common knowledge to solve it but could not. in the code segment below, I want to be able to loop through a dataset to extract value, but i keep getting the error as metioned "object reference not set to an instance......". as u can c, the objects i used are instantiated, please can anyone help solve this problem?
Dim dset1 As DataSet
Dim dt As DataTable
dSet1 = New DataSet
'The adapter stores the data in a dataset
dAdapt1.Fill(dSet1, "Patient Profile")
dt = New DataTable
dt = dSet1.Tables("Patient_Profile")
For Each rw As DataRow In dt.Rows --> Error Object reference not set to an instance of an object.
decdata = New TripleDES()
deRecDataFnam = decdata.Decrypt(rw("FirstName"), ned)
listItem = New ListViewItem()
listItem.SubItems.Add(deRecDataFnam)
ListVwPatProf.Items.Add(listItem)
Next
Thanks a lot!
|
|
|
|
|
ChiSmile wrote:
dt = New DataTable
dt = dSet1.Tables("Patient_Profile")
Yes, you're indeed initializing dt , but then you're reassigning it the value of dSet1.Tables("Patient_Profile") . Make sure you actually have a table in dSet1 called Patient_Profile .
Adam Maras | Software Developer
Microsoft Certified Professional Developer
|
|
|
|