|
With the BCL ToolBar class, you have to get the mouse coordinates (this is easy), convert to client coordinates in relation to the toolbar (call PoingToClient on the toolbar instance) and enumerate your toolbar buttons to find out over which the point lies.
For most applications, I recommend you go with a decent 3rd-party toolbar. They have a lot more functionality.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
The Scenario
I've created a custom control that has a public property that is of an enumerated value type. I have created an accessor method to get/set that property and have it 'binded'. Finally, in the constructor for the control, I set that property to a default value, referencing the full namespace of the enum value type to ensure no conflicts with other controls would exist (see sample code below):
<br />
namespace MyControls {<br />
<br />
public class MyCustomControl : System.Windows.Forms.Label <br />
{<br />
public enum MyLabelType { High, Low, Special, Hidden };<br />
<br />
private MyLabelType myLabelType;<br />
<br />
public MyCustomControl <br />
{<br />
myLabelType = MyControls.MyCustomControl.MyLabelType.Special;<br />
}<br />
<br />
...<br />
<br />
[Bindable(true), Category("Custom Properties"),<br />
Description("My Custom Control ...")]<br />
public MyControls.MyCustomControl.MyLabelType LabelType<br />
{<br />
get ... <br />
set ...<br />
} <br />
<br />
...<br />
<br />
}<br />
}<br />
The Problem
I drop the custom control onto a form and set my properties without a hitch. I add a using clause to my code for that namespace and do a build. I get no errors, I can run the application without issues ... Etc. However, if I close the solution/project, and open it back up, then open that form back up in design mode, I get errors on that enumerated property that indicates "The variable 'MyLabelType' is either undeclared or was never assigned".
When I attempt to set a variable to this value type my code, the intellisense doesn't "find" the enum value type. (Example):
MyControls.MyCustomControl.MyLabelType is not found ...
Yet if I open custom control solution in studio, rebuild it, and then go BACK to my solution that uses the custom control, studio can now "see" the enumerated data type ...
I have tried to set the "DefaultValue" on the property accessor for this type, but to no avail. It does not seem to affect the outcome.
Any suggestions or answers as to what I am doing wrong, or to why this is happening? I'm guessing the solution is something simple that I am just overlooking.
TIA
D.
|
|
|
|
|
I'm trying to pass a reference of Form1 to Form2 so I can change things on Form1 from Form2.
Here is my logic:
Form1
private void btnShow_Click(object sender, System.EventArgs e)
{
FormTwo = new Form2(ref this);
FormTwo.Show();
}
Form2:
public Form2(ref Form1 PassingForm)
{
InitializeComponent();
FormOne = PassingForm;
}
error CS1605: Cannot pass '<this>' as a ref or out argument because it is read-only
i can read the error, .. but what would the proper logic be here?
|
|
|
|
|
You don't need 'ref', because a Form1 is already a reference type. The error occurs because you're trying to pass a reference to 'this', which cannot be changed.
Personally I find reference languages confusing, because of the nature of aliasing and that there are no clues in the syntax indicating whether you're dealing with a value (which uses a shallow copy) or a reference (which merely copies the reference).
|
|
|
|
|
Hey,
I have a listview bounded to a dataset.
I have also 2 textboxes. These textboxes are in the same listview.bindingcontext.
listview.BindingContext = new BindingContext();
txt1.BindingContext = listview.BindingContext;
txt2.BindingContext = listview.BindingContext;
The listview has an event : selectedIndexChanged
I can also sort the listview.
How can I set the bindingmanager.position in the selectindexchanged event too the right record-index in my dataset?
After sorting, the index in the listview is not the index of the record in the dataset.
With custom collections, when I add an object I give it an internal id. So, I will always find the right object.
With a dataset I can not give him an internal id, because dataset is filled up with the sqldataadapter.
Thanks
|
|
|
|
|
I have a windows form with two tabpages. On the form load I want to move the second tabpage to the front(or have it display). Any ideas on how to do this? I have tried using tabPage2.focus. Didn't work.
thanks
Jubal
|
|
|
|
|
Have you tried:
<br />
MyTabControl.SelectedTab = tabPage2;<br />
I think that works....
|
|
|
|
|
How to Active C# form in MFC project?
|
|
|
|
|
Hi,
Is that possible to version a solution ?? If yes please help me out.
We have 2 phases in our web application project. Now the 1st phase is over. 2nd phase is coming now. Now, the question is how I maintain 1st phase changes in the solution. Can I version the phase 1 solution ?
Client is using phase 1 solution now. So any changes if they say we shd be in posn to incorporate not any phase 2 requirement.
Please let me know how I go about this. I have an idea of maintaining two different solution in the VSS. But is that possible to have strong name and version it ?
There are ASPX file also can I version it that also ??
Regards
Srinath
|
|
|
|
|
I'm not certain I'll have the exact answer you're looking for, but I'll mention a few things here (also not entirely certain I know what it is you are looking to achieve) ...
If you're using VSS, lock your code down and branch the solution/project. You'll then have a version 1.x.x.x branch and a version 2.x.x.x branch; course, you have to name them yourself.
In the application AssemblyInfo.cs file, you can specify the AssemblyVersion there. By default, it's specified as version ("1.0.*"), and the compiler automatically increments the minor build numbers. Once you've branched your code out, change that to ("2.0.*"); and so on ...
Also, you can create an AssemblyKey file that's different for each release. This is also contained in the AssemblyInfo.cs file that's part of your main solution.
Perhaps if you explained what it is you want to have happen, or not have happen, I could better point in the correct direction(?) ... maybe.
Hope some of that information helped ...
D.
|
|
|
|
|
Why should he use a different key pair for each release? This, in effect, identifies you as the company. Maintaining version bindings between releases is done using the <runtime> section of the .config file, or using a publisher policy assembly installed in the GAC.
I mean, I agree with the rest of the stuff, I just don't get the latest direction.
It's sort of like Authenticode; you buy an X.509 certification with the right extensions and sign your code with it. It identifies your company - much like assembly key pairs, except X.509 can be traced by easily to the source.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath,
Yes, this was my mistake and failure to properly explain Strong Name Key signing, thank you for pointing out this error. In hind sight, I'm not certain what I was trying to communicate regarding signing of his assembly ... it appears he's provided more information, so I'll have to review that before more information can be provided.
Thanks again for pointing this out,
D.
|
|
|
|
|
Douglas,
Thanks for the solution.
Let me explain you my requirement more elaborately.
I have a solution which contains 4 projects. Now we need to freeze the current version(say i freeze to ver 1.0.0.1). There might be some requirement changes with respect to ver 1.0.0.1.
Now there are set of new requirements coming up for the same solution. I dont want to touch prev version, I want to create a new version. Which can hold the new changes.
So changes /bug fixes with respect to ver 1.0.0.1 should not tamper ver 1.0.0.2 (my second ver 2)
Client shd be able to see changes w.r.t ver 1.0.0.1 after all they are god to us.
hope you got my problem
So please help me
Regards
Srinath
|
|
|
|
|
Hi Douglas,
Even if I version it, suppose I make changes in version 1, Can I replicate the same in version 2 during the release. Since version 1 goes for some changes I need to have those changes in version 2 only during the final release.
hope you got it. hope I am not bugging you
Regards
Sri
|
|
|
|
|
Sri,
If I'm understanding you correctly, your concern is with having to maintain two different releases. Meaning, your client will have version 1.0.0 at their site while you're working on the next release 2.x.x ... during this time, the client could encounter bugs/design flaws, which you'll have to fix in their build and make a point release (1.0.1) and you want a way to replicate that 'fix' into your 2.x.x code ...
There is a way to do this using VSS, however, it is often times more complex than just cutting and pasting your fixed code between the two releases. VSS provides a means to "share" branched code between releases. If the code segment is not different between your branches, then your "replicate my fix between versions 1.0.1 and 2.x.x" would work. HOWEVER, if you've modified that code segment already for your 2.x.x release, then that segment is no longer 'shared' and you would have to manually copy your fix between releases. You can find more information on this concept in the VSS help system (look at Shared code and Branching); you may have to read the help installed on the VSS server, since I believe branching is an VSS Admin function ... (you'll have to figure this out yourself).
It is my personal opinion, however, that it is far easier, and a better practice, to make your fix in your version 1.0.x code base and then manually copy that fix over to your 2.x.x build. When you turn your code over to your QA group, they should regression test all those 1.0.x point release fixes you made, in the newer 2.x.x build, to ensure they are indeed fixed. Doing this, also helps ensure that (1) the bug was actually fixed as thought and (2) that newer code introduced in your new build has not directly affected your previous fix (not that this would ever happen ...)
That's my two cents,
D.
|
|
|
|
|
I'm trying to write an app that handles system restore related stuff and would like to know how to convert the VBScript(s) in the following page into C# equivalent:
http://support.microsoft.com/default.aspx?scid=KB;en-us;295299&
|
|
|
|
|
Look at the System.Management.ManagementClass class.
My quick stab looks like:
ManagementClass mc =
new ManagementClass( @"\\.\root\default:Systemrestore" );
mc.Get();
mc.InvokeMethod(
"CreateRestorePoint",
new object[] { "this is a test", 0, 100 }
); However, this didn't appear to do anything - but then I may be misunderstanding the underlying API.
|
|
|
|
|
Thanks. It works (at least on WinXP) but i'm wondering how to get the other one to work :
set SRP = getobject("winmgmts:\\.\root\default").InstancesOf ("systemrestore")
for each Point in SRP
msgbox point.creationtime & vbcrlf & point.description & vbcrlf & "Sequence Number= " & point.sequencenumber
next
|
|
|
|
|
After a bit of trial and terror:
ManagementScope scope =
new ManagementScope( @"\\.\root\default" );
scope.Connect();
SelectQuery sq = new SelectQuery( "SystemRestore" );
ManagementObjectSearcher mos =
new ManagementObjectSearcher( scope, sq );
foreach ( ManagementObject mo in mos.Get() )
{
Console.WriteLine(
"{0}: {1}, sequence no {2}",
mo[ "CreationTime" ],
mo[ "Description" ],
mo[ "SequenceNumber" ]
);
} When investigating a ManagementObject , you may find the Properties collection helpful.
|
|
|
|
|
Thanks a lot! I'll put your name in the credits for this
|
|
|
|
|
int x=0,y=4,z=0;<br />
Console.WriteLine("Hello\n");<br />
x = Console.Read();
z = x + y; <br />
Console.WriteLine(" x + y = {0}", z);
All the rest of the code is a general Console app
I know this is simple but I am not sure why i am not getting 9 when i enter 5 for x. Using vs.net 2002. What am i doing wrong, not very experienced in c#.
|
|
|
|
|
My friend, the Read command is reading the 5 that you enter as a character. The ASCII code for 5 is 53, and x becomes 53. So you see...
|
|
|
|
|
Xarx wrote:
x = Console.Read();
Convert the "5" (53) to the value 5:
x = Int16.Parse( Console.Read() );
|
|
|
|
|
<br />
int x=0,y=4,z=0;<br />
Console.WriteLine("Hello\n");<br />
x = Int16.Parse( Console.Read() ); <br />
z = x + y;<br />
Console.WriteLine(" x + y = {0}", z);<br />
<br />
<br />
Is there something else that is required? I am getting two errors now on the new line.
C:\Dev\ConsoleTest1\Class1.cs(19): The best overloaded method match for 'short.Parse(string)' has some invalid arguments
C:\Dev\ConsoleTest1\Class1.cs(19): Argument '1': cannot convert from 'int' to 'string'
Again thanks in advance if I am missing something very simple, I figured this worked just like cin =\
|
|
|
|
|
Try Console.ReadLine(), it returns a string that is the required input parameter type for Int16.Parse.
|
|
|
|
|