|
Hi all,
Do we have Toggle Button Control in VS2005?
Please tell me how to work with ToggleButton
I need to use two buttons- if i select one the other should be desibled,vice versa.
Hope u got my question.-Just a sample Toggle Button.
Please help me.
pashi
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
I'm just about to release a button class with special state support for this capability, but it's easy to toggle any state of any set of controls by a standard pattern.
One technique is to assign a tag value to each member of your toggle group, iterate the controls belonging to the visual container, and toggle the states of all the other controls belonging to the tag group to the alternate state. I usually populate a separate list with controls belonging only to the toggle group. This approach iterates only the relevant controls and is not limited to the controls of a given container. In any case, the process is something like this:
public partial class Form1 : Form
{
ADVANCEIS.Controls.GlossContourButton B1, B2, B3, B4, H5, H6, H7;
List<ADVANCEIS.Controls.GlossContourButton> ToggleGroup_GlossButton = new List<ADVANCEIS.Controls.GlossContourButton>( );
public Form1( )
{
InitializeComponent( );
H5 = new ADVANCEIS.Controls.GlossContourButton( );
H5.SetBounds( H4.Bounds.X + w1 + ( w1 / 2 ), t, w1, w1 );
this.Controls.Add( H5 );
H5.Click += GlossButtonToggleGroupHandler;
ToggleGroup_GlossButton.Add( H5 );
H6 = new ADVANCEIS.Controls.GlossContourButton( );
H6.SetBounds( H5.Bounds.X + w1, t, w1, w1 );
this.Controls.Add( H6 );
H6.Click += GlossButtonToggleGroupHandler;
ToggleGroup_GlossButton.Add( H6 );
H7 = new ADVANCEIS.Controls.GlossContourButton( );
H7.Down = true;
H7.SetBounds( H6.Bounds.X + w1, t, w1, w1 );
this.Controls.Add( H7 );
H7.Click += GlossButtonToggleGroupHandler;
ToggleGroup_GlossButton.Add( H7 );
}
public void GlossButtonToggleGroupHandler( object sender, EventArgs e )
{
ADVANCEIS.Controls.GlossContourButton s = sender as ADVANCEIS.Controls.GlossContourButton;
if ( null != s )
{
foreach ( ADVANCEIS.Controls.GlossContourButton b in ToggleGroup_GlossButton )
{
if ( s == b )
s.Down = true;
else
b.Down = false;
}
}
}
-- modified at 0:50 Tuesday 20th February, 2007
|
|
|
|
|
Thnx mr.mike
See here my requirement is
i just need to take two buttons(as toggler)
when user click on the first button(say showbutton) the functionality should be accepted(in button_click event)
when the user clicks the second button(say Hidebutton) the button should be into hide position(i mean, should become dull)
so, please tell me what to do?
do i need to depend on any other 3rd party controlls/components or Does VisualStudio2005 has this feature?
plz help me
thnx and regards,
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
All you have to do actually is add your needed functionality.
However you create your buttons, you need to add them to the list as in the previous snippet; and you need to assign each button's Click event to this handler (also as in the previous snippet). So, this much (setup) is just as before.
Why? The following handler identifies which button has been clicked as a necessary aspect of the toggle group functionality. You want to do that of course in one place.
I'll explain line by line.
Firstly, I did not use a generic list in the previous snippet because I needed to test different kinds of controls. Others may have noticed that if we were processing one class, it would have been more appropriate to use a generic list instead. Then you would not have had to test if the sender is of the intended class; and the only reason (therefore) that you have toere test for null in the following code is that the first line will return null if sender is not a member/descendant of the tested class. As the previous snippet is flexible enough to handle various classes, I provide it again as an example of how to do so. Its further advantage (as stated in my previous explanation) is that it can process various controls which are not children of the same visual container.
1. So, here, we need to declare a local variable s which is assigned the result of a comparison that tests if sender is the intended class:
ADVANCEIS.Controls.GlossContourButton s = sender as ADVANCEIS.Controls.GlossContourButton;
If sender is ADVANCEIS.Controls.GlossContourButton, the value of s will be a reference to sender which we can now process further. If sender is not a member of this class, the value of s will be null, which we do not want to process because it is not a member of our toggle group, or is not a class with the Down property which this particular class has... which allows us to toggle a representative state. My previous example set the drawing state of the button to down to represent the toggled state.
What you may be asking (re: "dull") may not be a practical representation, because for instance if you mean disabled ("not enabled"), the effect you are wanting to use to represent the toggled state *may* lock your buttons out of being able to function further: each disabled button can no longer be clicked to toggle a state otherwise. If your scheme is to toggle that button back to enabled again by clicking an enabled button, your process/scheme will be fine.
2. Now, we simply test if sender is a class we want to process. You can omit this test if all the instances to which you are assigning GlossButtonToggleGroupHandler are members of the same class *and* if you are using a generic list. If not however, you must make this test, and this is the most efficient way to do so, because it avoids casting. This is a typical thing you would do in C++ for instance in writing (always) "safe" (exception impervious) code.
if ( null != s )
Tip: Always put your constants on the left side of your comparisons. Then the compiler will tell you when you make simple (typo) errors such as typing = instead of ==. As the constant cannot be assigned to, the compiler complains... actually identifying your typo simply because you have conformed to a standard of writing your constants on the left side.
3. Now we simply iterate our list, testing each b list member for being s (the sender).
foreach ( ADVANCEIS.Controls.GlossContourButton b in ToggleGroup_GlossButton )
4. If we identify the sender, the previous snippet set the sender button's Down property to true, indicating the toggled state. Your buttons may not have a Down property (which sets the drawn state of the button to pressed/down). I don't use the pre-packaged VS buttons. As to what you mean by "dull," I don't understand... but I assume you may mean disabled (as setting Enabled to false may be said to "dull" glyphs or text). So, in the following snippet I changed the original (class specific) assignments to toggle Enabled as you seem to be asking to do:
public void GlossButtonToggleGroupHandler( object sender, EventArgs e )
{
ADVANCEIS.Controls.GlossContourButton s = sender as ADVANCEIS.Controls.GlossContourButton;
if ( null != s )
{
foreach ( ADVANCEIS.Controls.GlossContourButton b in ToggleGroup_GlossButton )
{
if ( s == b )
{
s.Enabled = false;
if ( sender == MyButton1 )
{
DoMyButton1Stuff( );
}
else if ( sender == MyButton2 )
{
DoMyButton2Stuff( );
}
}
else
b.Enabled = true;
}
}
}
Tried and tested. Simple. Keep this pattern around, because you will use it your whole career.
|
|
|
|
|
|
I'm doing final testing on a library project and have an issue with OnSystemColorsChanged, which I have overridden as follows:
<br />
protected override void OnSystemColorsChanged( EventArgs e )<br />
{<br />
base.OnSystemColorsChanged( e );<br />
<br />
if ( MyCondition )<br />
{<br />
DoWhatIHaveToDoHere( );<br />
}<br />
}
My visual control will sometimes paint itself in derivatives of SystemColors.Control, and so I need this override to respond to changes by re-processing whatever color is assigned to it.
To test, I've gone into system settings and changed the base color for 3D objects. Colors in many simultaneously opened applications change, but not my control.
My problem is that my override is never entered. Is there some further way that we are supposed to register our component with the form or something to get OnSystemColorsChanged to fire? Or is what I am doing to test entry not sufficient to fire the method?
(I assume that Trace will enter the method, and that the fact Trace does not enter the method indicates it is not being fired -- besides of course the fact no processing occurs. )
TIA,
m
|
|
|
|
|
I don't know about the rest of you, but I encounter so many dysfunctionalities in visiting Microsoft sites that there hardly seems any point in trying. I have to log in to post (but I already logged in). I try to log in again, I'm told I have to enable cookies (but cookies are enabled). I try to post or send feedback, and I'm told I need to log in. I try to log in, but I'm told I'm already logged in.
This stuff is absolutely ridiculous.
In any case, I called and got a special link that was supposed to allow me to post a report without logging in... but it required me to log in as well, and we went around in circles for naught again...
BUT...
Though all previous searches turned up nothing, I tried my OnSystemColorsChanged search from that page... and I turn up an issue:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=95463
So, although this is not the whole issue, it reports that at one time, though system colors may be reconfigured, the new colors were not assigned to the values representing system colors. MS claims to have been able to reproduce the problem, and to have fixed it.
I believe their test situation was not broad enough to verify *also* that OnSystemColorsChanged is entered, because my testing shows no entry into this event handler whatsoever. Same problem with OnEnabledChanged, which I was able to work around by writing a new Enabled property.
OnSystemColorsChanged however provides no such opportunity, because of course we are not assigning to a property to fire the event -- it is a system event, the whole responsibility for which is Microsoft's.
Unless I misunderstand that my testing (manually resetting system colors) is somehow (?) insufficient to fire the event (it changes system colors in many other applications), I believe this establishes a compiler issue/bug.
If anyone knows any better, I surely would like to hear about it, because this is a very costly issue for us.
TIA,
m
|
|
|
|
|
My web site works fine inside the Visual Studio 2005 but when I publish it ( in my own computer ) it gives me this error message:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Server Error in '/SI' Application.
________________________________________
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0433: The type 'ProductDetails' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\si\9ce027e5\3d5cd3c7\assembly\dl3\9f893f96\30af096e_7654c701\App_Code.DLL' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\si\9ce027e5\3d5cd3c7\assembly\dl3\a3f57edc\d0156479_7654c701\App_Web_ypd3vqxs.DLL'
Source Error:
Line 122:
Line 123: [System.Runtime.CompilerServices.CompilerGlobalScopeAttribute()]
Line 124: public class productdetails_aspx : global::ProductDetails, System.Web.SessionState.IRequiresSessionState, System.Web.IHttpHandler {
Line 125:
Line 126: private static bool @__initialized;
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\si\9ce027e5\3d5cd3c7\App_Web_productdetails.aspx.cdcab7d2.unizty2q.0.cs Line: 124
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I don’t understand why 'ProductDetails' type exists in two different DLLs in my published site and why, as consequence, affects this application.
|
|
|
|
|
I don't think it's possible to tell from here, but it looks like you probably have references to two different versions of source which have different identifiers. Perhaps at one stage of your project you linked to a given version, then later to another. I would suggest removing the references, then carefully rebuilding them with only the finished files of the project.
|
|
|
|
|
I know I can create a multi dimension array using:
string[,] PageArray = { { "TextBox2", "Wilson" } };
But how do I add to the array ? For example, say I want to add "textBox3" & "Bob" as an element.
Thanks
|
|
|
|
|
string[,] PageArray = { { "TextBox2", "Wilson" },
{ "TextBox3", "Bob" } };
|
|
|
|
|
Once the array exists, you can't add to it. You need to use a List or something, instead. You can make a list of lists, to get a 2D effect. Or, you can create a struct to contain the two values you want in each element.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: Once the array exists, you can't add to it. You need to use a List or something, instead. You can make a list of lists, to get a 2D effect. Or, you can create a struct to contain the two values you want in each element.
This is a good point. I wasn't sure if he meant add in the sense of adding to an array after it has been created or add in the sense that he wasn't sure how to initialize it with the additional values.
Another possibility other than the ones you suggest is to use a Dictionary if his collection can be characterized as key/value pairs.
|
|
|
|
|
Good point, the Dictionary is a container that's hard to beat
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Are you sure he was not asking how to initialize the size of the array and then fill it in with information? Because that would just require setting the size for each dimention [5,5] for a 5x5. Then to add to the filled out dimensions you would just use array[0,0]= or array[0,1]=. If you use a multidimensional array I have found it really helps to map it out on paper first. Of course you could always just use a dictionary.
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
Hello!
I work in am TFS in my job ... and I receive a computer from another coworker and I need to login to TFS with my account...but VC# are login with his account.
Have anyone a suggestion about how can I change this.
thnx
|
|
|
|
|
My experience is, that TFS tries to log in using the username and password the computer was logged in with, if this fails, it pops up a login screen.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I am new to the whole c# world but I noticed something kind of strange to me. If I have an interface that has a property and I use both get and set in my implementing class, it doesn't break as long as I declare either get or set or both. If I use both, shouldn't the interface require me to declare both?
interface IReadThings
{
int Status { get; set;}
}
public class TheDoc : IReadThings
{
public int Status
{
get { return theStatus; }
set { theStatus = value; }
}
}
|
|
|
|
|
santhony7 wrote: If I use both, shouldn't the interface require me to declare both?
Nope. Say you have a readonly (get) property declared in an interface. In your implementing class, you have to implement the property with a getter. However, the setter is optional. If you implement a setter as well, it's not covered by the interface but is rather specific to the implementing class. For example:
using System;
using System.Collections.Generic;
using System.Text;
namespace InterfaceTest
{
class Program
{
static void Main(string[] args)
{
IReadThings things = new TheDoc();
int s = things.Status;
things.Status = 42;
}
}
interface IReadThings
{
int Status
{
get;
}
}
public class TheDoc : IReadThings
{
int theStatus = 0;
public int Status
{
get { return theStatus; }
set { theStatus = value; }
}
}
}
The above doesn't compile because "things" is a reference to the IReadThings interface. Thus it represents only the functionality declared by the IReadThings interface. Since IReadThings doesn't have a setter for the Status property, we get a compile error. Had we made "things" of type TheDoc , it would compile just fine.
The interface represents a blueprint that an implementing class must implement. However, the implementing class is free to provide additional functionality that goes beyond the interface's contract. This includes properties providing a getter or setter if one isn't specified by the interface.
|
|
|
|
|
Thanks man, that really helps. I understood about 69% of what you said but I am learning quick...
|
|
|
|
|
The only thing I might add to make this answer a bit more plain to understand is that Interfaces are often referred to as "contracts." That is, they represent an obligation of the implementing class to support whatever is declared in the interface. However, by no means are interfaces to restrict the implementing class to only what is promised in the interface.
|
|
|
|
|
How can I control the order that my properties appear in the DataBindings BindingSource selection dialog? Sorted alphabetic would be nice.
I have a business object that inherits from a bindingsource. Its properties appear to be in an apparent random order in the binding source selection dialog. For example when I'm selecting a property to bind to a text box text property.
|
|
|
|
|
I'm thinking you might be able to do something like that by inheriting from ExpandableObjectConverter. I'm not sure, but it'll give you something to try out.
public class MyClass : ExpandableObjectConverter
{
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(value, attributes);
return properties.Sort(new string[] {"Name", "Value"});
}
}
|
|
|
|
|
That was just the lead that I needed. I'm inheriting from a bindingsource and it implements ITypedList which has the GetItemProperties function. I overrode that function and simply added .Sort to base.GetItemProperties(listAccessors)
Thanks
|
|
|
|
|
Excellent. That's much more elegant. I believe my suggestion was a carry-over from 1.0 days. I know I did something like that (probably for a property grid) a long time ago.
|
|
|
|
|