|
Indexers allows to expose a group of values but how can i show those values in the designer so that the user can select one. I have to set other properties based on the selection made by the user. i guess indexers are availabe only in code on a object of that class.
Any other suggestions....
|
|
|
|
|
This works for objects:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public myVar MyProperty
{
get { return myvar1; }
set { myvar1 = value; }
}
don't know about enums though - maybe this will work
[DefaultValue(false)]
public myVar MyProperty
{
get { return myvar1; }
set { myvar1 = value; }
}
-spif2001
|
|
|
|
|
In fact, in the limited feature desired by you, I tried the method being used by you, and good news for you, it works!
The only change I made in your code (as shown above) is that I have used "public myVarEnum MyProperty" instead of "public myVar MyProperty" as used in your code (which appears to be a typing mistake), while defining the property.
In the sample small project prepared by me, the values "Mango" and "Peach" also persist if set at design time from the Property window from the dropdown. If you wish, I can separately send you the sample project files. Otherwise, I am including the source code of the MyButton.cs file (the inherited control) and the Form1.cs hereinbelow for your information:
using System;
namespace TestControl2
{
public class MyTextBox : System.Windows.Forms.TextBox
{
public enum myVarEnum {Apple,Mango,Peach};
protected myVarEnum myvar1;
public myVarEnum MyProperty
{
get { return myvar1; }
set { myvar1 = value; }
}
public MyTextBox()
{
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace TestControl2
{
public class Form1 : System.Windows.Forms.Form
{
private TestControl2.MyTextBox myTextBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.myTextBox1 = new TestControl2.MyTextBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
this.myTextBox1.Location = new System.Drawing.Point(184, 48);
this.myTextBox1.MyProperty = TestControl2.MyTextBox.myVarEnum.Peach;
this.myTextBox1.Name = "myTextBox1";
this.myTextBox1.TabIndex = 0;
this.myTextBox1.Text = "myTextBox1";
this.button1.Location = new System.Drawing.Point(88, 104);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.label1.Location = new System.Drawing.Point(88, 176);
this.label1.Name = "label1";
this.label1.TabIndex = 2;
this.label1.Text = "label1";
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Controls.Add(this.myTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
label1.Text = myTextBox1.MyProperty.ToString();
}
}
}
The last method button1_Click, puts the value "Mango" etc. in the label1 on Form1. Hope it solves your problem.
|
|
|
|
|
I want to add a delay at the end of my while loop, so that it executes once every 10 minutes but am unsure how that works in C#.
I've tried Thread.Sleep, but it doesnt delay the loop.
Any suggestions?
|
|
|
|
|
Use a timer, and when 10 minutes have elapsed, start your processing.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
how the timer can be used????????????????????????
It has lot of classes>>>>and members
please tell something in detail
|
|
|
|
|
It's actually very easy. There are two kinds of timers in the .NET Framework:
- Windows Forms timers (
System.Windows.Forms.Timer class), which you drag in the desinger to your form, set some properties, and write the code for the Tick event handler, and that's it. For your situation, the problem is that if the process is long, it will block your UI thread and your main form will not be responsible. - Thread timer (
System.Threading.Timer ). I have never used this one, but from the docs[^] it seems you set a timer, without requiring a form, that will run on another thread. So, your form keeps working normally while another thread does your processing on the background.
I believe the second one will suit your purpose better. But, as I have never used a System.Threading.Timer , I can't be of more help, since all I know is the same as you, what is included in the documentation.
If someone knows better, feel free to correct me please!
Good luck!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Thread.Sleep should work. What did you pass as the parameter? For 10 minutes, it should be 10 * 60 * 1000. But remember that Thread.Sleep would be less efficient than a signaling mechanism as Thread.Sleep would cause the Thread to use up CPU time...
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
|
Thread.Sleep() causes "busy wait", where the thread uses up its quantum of CPU time doing nothing. Waiting for a signal (or in general, any OS synchronization mechanism) causes the thread to be context switched for another immediately. This obviously results in performance benefits as other threads get a chance to run in the time that a "sleeping" thread would have spent doing nothing.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I have a collection of items. Each item has some events. I am exposing the collection through a property which shows up on the propertygrid of the form. I can edit the collection and all the persistance to the code is allreay taken care of.
One problem remain which I can't solve. I can't edit the events of each item like you can normaly edit with the form's events or the control's events. The collection editor don't show the event tab.
The main goal is to edit this collection like you edit a menu and it's items. You can edit the menu items events. My class is not for visual porpose and is been used on components, not just forms, so the solution of using a collection-Based Controls with Rich Design-Time Support http://www.codeproject.com/csharp/collcontrolsrichdes.asp
is not valid for this case.
Thanks in advance. Any help will be appreciate.
|
|
|
|
|
Hello all,
I Work with active X control i added it with " Add Reference" and i used the functions that it exposed to me in my code did it need any installtion code to setup or just i add a refrence to it in my code only.
Regards,
Hay
|
|
|
|
|
No need for any separate installation code.
The basic procedure for using ActiveX control in your Visual C# code is as under:
1. Add a reference to the type library containing the ActiveX control.
2. If you want to take advantage of the designer, add the ActiveX control to the Toolbox by customizing the Toolbox.
3. Now, drag an instance of the ActiveX control from the Toolbox to your designer to add it to your project at design time. This will add the necessary code to instantiate the control in your project. Alternatively, you can declare and then instantiate the ActiveX control in code and add it dynamically to your application at run time.
|
|
|
|
|
I am trying to crete a method that will convert an improper fraction to a mixed number...
I am not sure how about how to acomplish this. I know I can get the remainder with the modulus operator (%), but I am not sure how to get the quotent.
Any insight would be appreciated.
thanks
|
|
|
|
|
One method to get the quotient (or the whole number portion of the improper fraction) is to use a function such as under:
public int GetWholeNumber(int numerator, int denominator)
{
int wholeNumber = 0;
int tempNumber = Numerator;
while(tempNumber >= Denominator)
{
tempNumber -= tempNumber ;
wholeNumber ++ ;
}
return wholeNumber;
}
Or, alternatively, you can also try the following method:
int Numerator = 57 ;
int Denominator = 9;
int wholeNumber = (int) (Numerator / Denominator);
|
|
|
|
|
Hi!
I'm building a grid control which contains a grid of cell controls. Each cell is supposed to contain another control. Everything works fine except the design-time behaviour which I have two problems with. The first is to draw adornments on the cells, which are another control type contained within the grid control (sort of the same as a panel control)..
[Designer(typeof(LayoutGridDesigner))]
class LayoutGrid : Control
{
ArrayList<gridcell> gridCells;
...blabla...
}
[Designer(typeof(GridCellDesigner))]
class GridCell : Control
{
}
I've tried to make both the GridCellDesigner and the LayoutGridDesigner to paint a dotted line around (inside the border of) the GridCell. The gridcell won't paint anything - I expect this to be because child control don't seem to paint adornments. When trying to paint the adornments with the GridLayoutDesigner the gridcell keeps on repainting...
The second thing I want to do is to make the gridcells able to contain other controls. This works by making GridCellDesigner inherit from ParentControlDesigner instead of ControlDesigner, but as with the adornments it doesn't work when the gridcell is a child control..
Any suggestions?
|
|
|
|
|
HI
Need help, Does anyone know how , which code i should use to open an authentication window from the code? when using webclient features, Im talking about the same window that opens in the Gmail Notifier on the startup , the one that you get when trying to navigate to a protected 401 page.
i tried using the httputility class , but no luck .
please HELP!!!
Thanks a lot
MOshe.
thanks , moshe bar-oz
|
|
|
|
|
You cant, the IE auth window is part of IE. What you can do however is create your own dialog box with username/password. Create a network credential object from the username and password and assign it your webclient object's credentials.
Ryan
Ryan.
|
|
|
|
|
hi
thanks for replying , i think I can , there are objects of IE ??
So how Gmail doing that in their code?
thanks , moshe
|
|
|
|
|
Hi All:
Sorry, this doesnt really belong in this forum but I dont know which forum I can put this in.
I want to have a batch script that insalls a windows service with local system account priviledges. I know that if I install something I can just use the installutil program to do it, but how do I get it to have the system account priviledges?
Secondly, how do I programatically install a scheduled task?
Thanks a lot for your help,
Jim
Did I post well? Rate it! Did I post badly? Rate that too!
|
|
|
|
|
In your installer you can set the account that your service will install under.
Esmo2000 wrote:
Secondly, how do I programatically install a scheduled task?
Since you are running a service, you can just create a timer and execute anything you need to. If you specifically need a scheduled task then there are some articles on CP that will show you how to do it.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
andy brummer wrote:
In your installer you can set the account that your service will install under.
Sorry, this is a stupid question, but I don't see where I can do that. Can you give me hint what I need to be doing?
andy brummer wrote:
Since you are running a service, you can just create a timer and execute anything you need to. If you specifically need a scheduled task then there are some articles on CP that will show you how to do it.
I wish it were that easy, but my program is runnig asynchronously. I'm worried that the two might happen at the same time and I dont want two threads to be running at the same time in this program. Would you have any suggestions for stopping this from hanging on the next message?
The program structure for that is just a function that resembles:
set messageEventHandler functionName;
functionName
{
getMessage();
doBlah();
getNextMessageWaitIndefinitely();
}
Did I post well? Rate it! Did I post badly? Rate that too!
|
|
|
|
|
how do i access datapicker.value through Control reference
i cant get control.value
|
|
|
|
|
can you rephrase your question ?
Shardool Karnik
Lead Software Engineer
Compass Technologies, Inc.
http://www.compasstec.com
|
|
|
|
|
You have to cast the reference:
DateTimePicker dtp = ctl as DateTimePicker;
DateTime value = DateTime.MinValue;
if(dtp != null)
{
value = dtp.Value;
}
else
{
} I hope this helps!!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|