|
You'll have to paint the StatusBar or StatusBarPanel (whichever you use) yourself. See the StatusBar.DrawItem event documentation in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hai there,
In my project i have a user control that will display colordialogbox.
At a time user will create n- number of usercontrol and will choose different color for all different control. the color may defined or custom. My aim is to store all selected color to database.
How it is possible.
See, some times i will get user selected colors as Red,green,Blue etc. why because these colors are in color struct.
but if i choose color that is not in color struct that will give some values like this [A122,R=654,G=232 B=233]. How can i convert this values to meaningfull names that end user can identifiy easily ?
hai, feel free to contact
Sreejith SS Nair
|
|
|
|
|
sreejith ss nair wrote:
My aim is to store all selected color to database. How it is possible.
You could use int myIntColour = System.Drawing.ColorTranslator.ToWin32(myColour); to convert the colour to an int and store that value in the database. You can then use System.Drawing.ColorTranslator.FromWin32(myIntColour); to convert back to a .NET object
sreejith ss nair wrote:
but if i choose color that is not in color struct that will give some values like this [A122,R=654,G=232 B=233]. How can i convert this values to meaningfull names that end user can identifiy easily ?
If the colour is not already available as a named colour then you'll either have to make up some names yourself (a big task as there are 16.7million possible combinations) or get the user to name their own custom colours.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
sreejith ss nair wrote:
but if i choose color that is not in color struct that will give some values like this [A122,R=654,G=232 B=233]. How can i convert this values to meaningfull names that end user can identifiy easily ?
First of all, you can't use 654 for the red component. The only legal values are 0 through 255. Second, you should use a color picker - which many are available from this site and there is a way to use the ColorEditor that you see in the PropertyGrid for color properties like ForeColor and BackColor - which makes it easy for a user to pick a color. If you want to name these colors as Colin mentioned you'll have problems since the Color methods don't support user-defined names, so you'll have to come up with your own implementation, such as implementing read-only properties with pre-defined Color instances like the named colors already on the Color struct.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a listbox.
I want to get the selected item of the list and assign it as a hatchstyle to a variable
ie. hatchstyle = listbox selected item
please help
"joel"
|
|
|
|
|
See Enum.Parse . Assuming your ListBox contains a list of strings with corresponding HatchStyle enum member names, you can use something like this:
string value = listBox1.SelectedItem as string;
if (value != null)
{
try
{
HatchStyle hs = Enum.Parse(typeof(HatchStyle), value);
}
catch
{
MessageBox.Show("Invalid hatch style!");
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
this works
HatchStyle htch = (HatchStyle)this.listBox1.SelectedItem;
I dont know how but it does.
|
|
|
|
|
I have created an Windows Invoice programme in C#, with Visual Studio 2003, which has 4 textBoxes by 15 line items.
The 4 boxes are Description, Quantity, Rate, and Amount.
How do I immediately show the Amount as calculation with Quantity * Rate.
I currently can only show the calculated Amount after Saving or Updating the Invoice.
All previous help from this site has been excellent.
Thank you, in anticipation.
Fred S. Parker
Email: fred@fsparker.com.au
|
|
|
|
|
Check into the TextChanged event. It'll fire whenever the text changes in a textbox. You could probably get away with one function handling the TextChanged event for all of your Quantity and Rate textboxes. Then it's just a simple matter of Amount = Quantity * Rate.
RageInTheMachine9532
|
|
|
|
|
Dave,
Thank you for your prompt reply.
Can you point me to a pratical sample of your suggestion.
Regards,
Fred.
Fred S. Parker
Email: fred@fsparker.com.au
|
|
|
|
|
Out of curiousity, why not use a DataGrid and bind that to either a DataSet or DataTable , or to an array of some class that you could implement? The DataTable already supports expressions like this and doesn't have to be tied to a database to be usable.
It's just a thought. Dave's right, though, just handle one of the events when the TextBox loses focus and update the product of the two TextBox es in your calculated TextBox . TextChanged is probably best for this, but keep in mind that it isn't fired till the TextBox loses focus.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath.
Thank you for your suggestion, but a DataGrid is not appropriate.
I have 3 other projects that require calculations, one which has a combination of 60 TextBoxes that require calculations.
Regards,
Fred.
Fred S. Parker
Email: fred@fsparker.com.au
|
|
|
|
|
Heath Stewart wrote:
TextChanged is probably best for this, but keep in mind that it isn't fired till the TextBox loses focus.
Text changed is fired whenever text is changed in the control (by either programmatic modification or user interaction). I think, you tought about Validating event which is truly raised when control loses focus.
But talking about textboxes and calculations...
You can:
1. Create data table as spoken above. But - do you want two way calculations? It means if user enter Rate and Amount, should the quantity be "reverse calculated" or not? In this case, use RowChange/ColumnChange evenmts to calculate values rather the expressions. There is one more disadvantage: You will need to bind 15 rows of the table at a time. I have been playing with it some time but not developped efficient way.
2. Create some calculator class, which can be bound with textboxes (or whatever control you want) and directly operate on datasource you want. I think, this method is much better, because you can validate data in the fly (esp. when input is bound to textbox), and calculating logic may be much more complex when you'll need it.
|
|
|
|
|
True, but his question had to do with updating a calculated field through user interface, so then my original reply is correct: the TextChanged event is only fired when the control looses focus. Trust me, I've been doing this for a very long time and it is even documented as such. The text one types isn't committed to the Text property until you leave the control and the event is fired in the set accessor for the Text property after the value is stored (rather, the WM_SETTEXT message is sent to the control with the text).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasstextchangedtopic.asp
and cite: This event is raised if the Text property is changed by either a programmatic modification or user interaction.
Heath Stewart wrote:
so then my original reply is correct: the TextChanged event is only fired when the control looses focus
I've even coded a little toy to play with textbox events, and on my system (WinXP Pro, .Net 1.1) the TextChangedEvent is fired everytime user changes the text, not when control loses focus.
using System;<br />
using System.Windows.Forms;<br />
using System.ComponentModel;<br />
<br />
namespace WindowsApplication47<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private System.Windows.Forms.TextBox tb;<br />
private System.Windows.Forms.ListBox lb;<br />
<br />
public Form1()<br />
{<br />
this.Text="TextBox events:";<br />
lb=new ListBox();<br />
lb.Dock=DockStyle.Fill;<br />
this.Controls.Add(lb);<br />
tb=new TextBox();<br />
tb.Dock=DockStyle.Top;<br />
this.Controls.Add(tb);<br />
tb.TextChanged+=new EventHandler(tb_TextChanged);<br />
tb.LostFocus+=new EventHandler(tb_LostFocus);<br />
tb.Validating+=new CancelEventHandler(tb_Validating);<br />
}<br />
private void tb_TextChanged(object sender, EventArgs e)<br />
{<br />
this.AddToList("TextChanged. Current text is:"+this.tb.Text);<br />
}<br />
private void tb_LostFocus(object sender, EventArgs e)<br />
{<br />
this.AddToList("LostFocus.");<br />
}<br />
private void tb_Validating(object sender, CancelEventArgs e)<br />
{<br />
this.AddToList("Validating.");<br />
}<br />
void AddToList(object val)<br />
{<br />
this.lb.Items.Add(val); <br />
this.lb.SelectedIndex=this.lb.Items.Count-1;<br />
}<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
}<br />
}
Could you play with this toy a while and tell me where are lost focus and other events you are talking about?
btw:
This may be true if we are talking about databinding. The difference is that the control itself does not ends "editing" of the current datasource (ie. row). So then the magic formula:
this.textBox.DataBindings["Text"].BindingManagerBase.EndCurrentEdit();<br /> in TextChanged event routine makes data immediately changed in datasource.
|
|
|
|
|
The TextChanged event is not fired for every character typed - only when the text is committed, when happens when you programmatically set the Text property, when the control looses focus, or anything else that causes the typed text to be committed to the Text property.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How can i enter data from windows form into array. How would this form look (for entering array).
|
|
|
|
|
It might be a bit advanced, but using TypeConvertors and UITypeEditors (especially the ArrayEditor) will do the best job
|
|
|
|
|
How many times are you going to ask this question?
What the form looks like entirely up to you!
You could either have a single textbox that the user has to input all the values in, seperated by some delimitter that you dictate. (Not a good idea...)
Or you could have a bunch of textboxs arranged on the form, in a kind of grid, that the user could fill in one at a time. Then you just take all those values and put them into your array.
Or, whatever else you come up with...
RageInTheMachine9532
|
|
|
|
|
It depends on how many entrys you want in the array.
If the array don't have a fixed lenght, I would have used a ListView to view all the items in the array. I would then have buttons to Delite and modefie the selected item, and a button to add a new item.
Hope it helps
Thomas
|
|
|
|
|
|
I want to hide my windows frame and toolbar when mouse is not hovering on them. Just like windows media player. Any idea?
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Hi!
I have implemented this behaviour to hide the MainMenu of my application.
I start an extra thread, which runs in the background with lowest priority, so it doesn't affect the performance and gets terminated by the CLR once all foreground threads belonging to the process have terminated. The thread executes an endless loop which checks if the Cursor.Position is over the area where my menu should be displayed.
If so, i assign the instance of my MainMenu to the Form.Menu property, so it is displayed. Additionally i move all controls in my Form upwards, so it seems they stay at the same place.
Does this help?
|
|
|
|
|
Thanks for your reply. Yes it helps and give some idea. But of course I don't know how to access to ToolBar . I'll dig into to it more and also waiting for other CPains reply.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
By declaring a field for the ToolBar (like VS.NET does by default) and referring to that field when you need to hide or show it. If another class will be accessing your toolbar, then make a read-only public property (i.e., not set accessor) that exposes your ToolBar to other classes. Make sure you cast any "generic" Form reference to your actual Form -derivative class in order to access the public property.
Microsoft MVP, Visual C#
My Articles
|
|
|
|