|
That depends on your requirements. Most of the time, you don't need to exposes the ENTIRE set of properties of the constituent control(s). You can supply properties to expose only the control properties you need or none at all and write your UserControl properties and methods to control the constituent controls internally.
|
|
|
|
|
I basically came to the same conclusion after I started thinking about it. Each constituent has a ton of properties you would never want to even see from a user control point-of-view.
|
|
|
|
|
If you want designer support, you would need to expose the control via a property and then write your own CodeDomSerializer to write to the form.designer.vb file.
|
|
|
|
|
Hold on though. I thought the whole idea of a usercontrol was to be able to access all of its properties just like any other control, even if that control has consituent controls inside it. I am curious as to why it is so difficult to get to those properties.
|
|
|
|
|
The point behind a UserControl is to create a custom control with a bunch of other controls as children, all working as parts to solve a common goal.
For example, a TextBox and a button next to it can be placed in a UserControl. The TextBox can be ReadOnly and the button is clicked, opening a OpenFileDialog that lets the user pick a path and you can then put the path into the TextBox and have that path returned as a property of the UserControl. The user does not get to type in the TextBox.
The only property the UserControl would expose would be the path selected, not any of the properties of the TextBox or Button.
|
|
|
|
|
In that regard, it dawned on me after I wrote that that if you had 4 constituent controls in a usercontrol, that is a hell of a lot of properties to have to expose, especially since many of those properties have the same names for different controls...A big mess when you really aren't concerned with those properties outside the user control.
|
|
|
|
|
Sorry, I did not think that one over enough before posting it.
You would not need a custom serializer if you exposed the child control's properties as properties of the UserControl. Basically it comes down to the fact that you need to write some code to expose properties of the children controls in the VS designer.
As for your comment, Dave's response says it very well. The only thing that I would add to that, is that the usercontrol template facilitates the visual design process.
Also, here is good article on the subject link.
|
|
|
|
|
Thanks for that info, and the great link.
So basically, declaring properties is the only way to get those properties to the user. Which is great from a control management point-of-view, but necessarily a lot of work, if for some hypothetical reason, you needed to expose all the constituent controls' properties. But, now that I've been thinking about this and reading all of your replies, it's hard to imagine why that scenario would even exist.
|
|
|
|
|
Quote: So basically, declaring properties is the only way to get those properties to the user.
Not exactly. And I don't know why I did think of this earlier.
Assume you place the UserControl in a class library.
As previously mentioned, you could change the child control's access modifier to Public and it would show up in the property grid and you could try to set it's properties. They would appear as set in the designer, however any of the changes are only held in Visual Studio's memory and not written to disk as part of the designer generated code. Building the project would clear any of these apparent property changes. To avoid confusion in the designer, I would set the access modifier to private and expose it through a property like this:
<System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Content)> _
<System.ComponentModel.Browsable(True)> _
Public ReadOnly Property ExposedTreeView As TreeView
Get
Return TreeView1
End Get
End Property
This allows you to reference the child control in both code and via the property grid for the placed UserControl. The magic is in the DesignerSerializationVisibilityAttribute. It tells the designer to write the changes to the Form.designer.vb file.
|
|
|
|
|
I'll take a gander at that one. Sounds nice and elegant.
|
|
|
|
|
I have three Comboboxes
cmbA, cmbB, cmbD and datagridview1, Button1, button2
by button1 click, I want to add 1st rows to datagridview1
click again add 2nd rows
by button2 click i want to delete selected rows.
please help me to solve this by providing sample code snippet
|
|
|
|
|
Posting a specification and asking for code will not garner much of a response.
What have tried thus far? (show your code)
Explain what part is not working, and people will be willing to help you solve the problem.
|
|
|
|
|
Hi,
I have working with sockets i want to play youtube videos using sockets please help me
|
|
|
|
|
|
You can't. This violates the YouTube terms of service. You MUST use their player and nothing else.
Besides, if YouTube doesn't have a server listening for your client what are you going to connect to???
modified 9-May-13 10:22am.
|
|
|
|
|
I have to admit, this is probably about as basic as it gets, but I must confess ignorance on this, and I cannot seem to find an answer anywhere. It goes like this:
I have an If/EndIf block:
If ValueA And MaskA Then<br />
' Do stuff.<br />
End if
Now, I look at that and my first reaction is to knee-jerk and expect that the above If-line is written incorrectly since a bitwise operation has been evaluated but no condition on it has been defined. In other words, I would expect it to be written more like:
If ValueA And MaskA = 1 Then<br />
' Do stuff.<br />
End if
I ran the first example and, indeed, it seemed to work OK. So then it seemed that vb.Net can treat such an expression in a special way, assuming that such a line before being evaluated is "0" (False) and then POSSIBLY, not zero AFTER evaluation, making the result "True".
Then, based on that assumption, I needed a reverse logic, so that if the condition was False, it would execute rather than when it is True:
If Not (ValueA And MaskA) Then<br />
' Do stuff.<br />
End if<br />
However, that does not work since all that does is essentially take the binary digits and flip them, turning the result into a negative value (a signed integer).
So now it seems that the only solution is to set the block up as an If/Else block:
If ValueA And MaskA Then<br />
' Do stuff.<br />
Else<br />
' Do alternate stuff.<br />
End if<br />
That should ALWAYS work, I would tend to think.
But if my above logic has been perfectly consistent, then the 2nd example in this post, should also work, but with a test for the value "0":
If ValueA And MaskA = 0 Then<br />
' Do stuff.<br />
End if<br />
Alas, it failed, since vb.Net seems fixated on interpreting the result as having to be a Boolean, so my above logic is flawed somewhere. Even though evaluating the result in the Immediate window returns "0", the code does not execute.
What IS the vb.Net convention for using bitwise operators in an If-conditional statement?
Hopefully the answer to this question can solve the riddle of Global Warming and lead to cures for all diseases! )
|
|
|
|
|
If there is no explicit comparison in the condition expression, it is automatically compared to zero. Non-zero values result in True, zero results in False.
Your expressions seem to be dependant on having a bit be 0 or 1. You could rewrite your expression to be a bit more explicit by specifying what the result of the bitwise operation should be. For example, if you need to check the 7th bit for a 1, then you would use something like:
Private Const MASK As Integer = &H40
If (someValue And MASK) = MASK Then
End If
|
|
|
|
|
But that is similar to the following (in principal), which failed to execute the cotained code when the result was zero:
If ValueA And MaskA = 0 Then<br />
' Do stuff.<br />
End if<br />
|
|
|
|
|
|
If (ValueA And MaskA) = 0 Then<br />
' or<br />
If Not (ValueA And MaskA) Then
After testing, the first example works, the second does not. For the first one, I see now the importance of hierarchy and the parens. For the second, I don't think it works because it is performing a binary NOT on the result, thus turning it into a negative number (or just a huge unsigned integer). At any rate, since it is now a non-zero number, the final condition is "True", and the intended action fails.
|
|
|
|
|
Show the values of ValueA and MaskA you used for your test.
Do you understand that (6 AND 5) = 4 ?
|
|
|
|
|
treddie wrote: After testing, the first example works, the second does not
Oh, it works, just not the way to think it does.
The result of (ValueA And MaskA) results in an integer value, not True/False. That integer is compared to zero. If the result of the expression is non-zero, True is returned. The Not operator will invert that to False.
If the result of the expression is zero, False is returned, then inverted to True by the Not operator.
Withouting seeing the values of ValueA and Mask, it's pretty much all we can tell you.
|
|
|
|
|
The Not operator will invert that to False.
But that is not what happens. Here are some actual tests I performed:
The value and the mask in these examples are:
FileAttributes Value that contains a bit field that indicates whether a resource is a folder or a file.
Folder = 8208D, File = 8224D
Mask Bit mask that tests for the presence of a folder (16D).
Option Strict is NOT set.
_____________________________________________________________________________________________________
GOAL: Run code on "True" condition (Resource is a folder):
If (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
'Execute code.
End If
When FileAttributes = 8208D (Folder):
8208D (Folder) = 2 0 1 0 H
0010 0000 0001 0000 B
16D (Mask) = AND 0000 0000 0001 0000 B
_________________________________
Result 0000 0000 0001 0000 B <> 0, ("True"), Code executes as it should.
When FileAttributes = 8224D (File):
8224D (File) = 2 0 2 0 H
0010 0000 0010 0000 B
16D (Mask) = AND 0000 0000 0001 0000 B
_________________________________
Result 0000 0000 0000 0000 B = 0, ("False"), Code does not execute.
This is correct.
_____________________________________________________________________________________________________
GOAL: Run code on "False" condition (Resource is a file):
If Not (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
'Execute code.
End If
When FileAttributes = 8208D (Folder):
8208D (Folder) = 2 0 1 0 H
0010 0000 0001 0000 B
16D (Mask) = AND 0000 0000 0001 0000 B
_________________________________
Result 0000 0000 0001 0000 B <> 0, ("True"), Code WOULD execute, if left as is.
_________________________________
NOT 1111 1111 1110 1111 B <> 0, ("True"), Code executes when it SHOULD NOT.
When FileAttributes = 8224D (File):
8224D (File) = 2 0 2 0 H
0010 0000 0010 0000 B
16D (Mask) = AND 0000 0000 0001 0000 B
_________________________________
Result 0000 0000 0000 0000 B = 0, ("False"), Code does not execute, if left as is.
_________________________________
NOT 1111 1111 1110 1111 B <> 0, ("True"), Code executes as it should.
________________________________________________________________________________________________________________________________________________________________
I can only conclude from all of this, that an If condition without an equality can only execute code on "True", and never on "False".
|
|
|
|
|
OK. You should be testing the value of the bitwise operation against the value of the mask, NOT depending on an implied true or false.
|
|
|
|
|
That is the difference between a logical and a bitwise expression. In your expressions you cannot use NOT to invert from non-zero (implied TRUE ) to FALSE . I think as Dave suggests you need something like:
If (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
Else
End If
or even
If (FileAttributes And FILE_ATTRIBUTE_DIRECTORY) = FILE_ATTRIBUTE_DIRECTORY Then
Else
End If
Use the best guess
|
|
|
|