|
Use the format method in the String class to show the number as you want.
Regards,
Satips.
Don't walk in front of me, I may not follow;
Don't walk behind me, I may not lead;
Walk beside me, and just be my friend. - Albert Camus
|
|
|
|
|
Gee - 5 people have already answered this, what did your answer add ?
Christian Graus - Microsoft MVP - C++
"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 )
|
|
|
|
|
Just now i signed in CG and i answered my suggestions for that.
Regards,
Satips.
Don't walk in front of me, I may not follow;
Don't walk behind me, I may not lead;
Walk beside me, and just be my friend. - Albert Camus
|
|
|
|
|
It added a nice , which none of the others did. I think flowers with an answer is the way forward on these forums.
It also knocked up his messages posted count by 1 - I reckon he's after your number one spot!! He'll be into thrash metal soon.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Yep. Wonder if Satips is listening to Ratt, Quiet Riot or Twisted Sister right now
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
damn..!!
i forgot that i asked a question at code project and not checked my mail
but thanks guy i will try to use format
|
|
|
|
|
Good luck to you with format. Any other questions, post it on CP and don't forget to check your email
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
yep, it worked as i wanted
|
|
|
|
|
Cool deal, man
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
FolderBrowserDialog control allows to select the folder name. But I want added feature where I can type in the folder name instead of selecting the folder. How do I achieve this?
|
|
|
|
|
Probably, you will have to write on your own.
|
|
|
|
|
Hi,
I have implemented a custom membership provider. I have a class called ProviderUtility. In this class I have a method called EncodePassword.
I want to use the EncryptPassword method, but when I type MembershipProvider. then the method does not appear. Can someone please explain how do I use this method? I did use using System.Web.Security; at the top of my class.
Regards
ma se
|
|
|
|
|
Do you mean that you've written a class derived from MembershipProvider ? In your own instance methods, you should simply call EncryptPassword , without qualifying it with the MembershipProvider name (which indicates use of a static method). Optionally, to indicate that you're calling a method in a base class, you qualify it with base . This is required if your class overrides the base class method if you want the base class method to be called rather than your own.
Otherwise, EncryptPassword is a protected instance method, so it can only be called by instance methods of MembershipProvider and instance methods of classes derived from MembershipProvider . Since you cannot call it from other locations, IntelliSense does not show it in the list of available methods. If you type the name of a class followed by a dot, IntelliSense shows you a list of all public , static fields, methods, events and properties of that class (and internal static ones if the code you're working on is a member of the same assembly).
|
|
|
|
|
hai,what is the main difference between "methods" and "get" "set" properties? In properties we can assign and return values , but the same thing is possible in methods also and even calling the properties and methods is also similar.my question is why we go for properties??
thank u
dot net !!! definetely a revolution
|
|
|
|
|
Hi,
you dont need properties, but they make things easier and more readable.
which statement do you prefer:
myForm.Width+=100;
myForm.SetWidth(myForm.GetWidth()+100);
|
|
|
|
|
- Some features of C# rely on properties: i.e. design support and heavy use of attributes
- Properties are inlined (if I'm not mistaken)
- property link a set and get "method" together.
- properties are used i.e. in xml serialization (properties are serialized by default, fields not (and methods of course, too))
- I think it makes code more readable then properties stand for the state of an object where as methods stand for actions on this state.
-^-^-^-^-^-
no risk no funk
|
|
|
|
|
Urs Enzler wrote: - Properties are inlined (if I'm not mistaken)
The IL generates get_ and set_ methods
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Urs Enzler wrote: Properties are inlined (if I'm not mistaken)
The JIT may choose to inline any method that's short enough. If a property setter or getter method is particularly long, it probably won't be inlined - the fact that it's a property is irrelevant.
The CLR doesn't really 'understand' properties or events - the compiler is responsible for compiling a call to the correct underlying functions. In C# they're always called set_Property , get_Property and add_Event , remove_Event respectively (for a property called Property and an event named Event ). The metadata links them into a single property or event. An standard event written in C# also has a field of the appropriate delegate type which is invisible to the user. It's possible to write an event which has custom add and remove methods; Windows Forms does this, making use of a list so that for example Control (which has 69 events in .NET 2.0) does not need to have 69 delegate fields unnecessarily bloating the memory footprint of each object. The feature is so useful that the implementation mostly lives in System.ComponentModel.Component 's Events property.
|
|
|
|
|
Properties and methods are semantically different.
The normal behaviour of a property is that it represents a single value in the object. Getting the value should not change the state of the object. Setting the value should not change the state of the object in any other way than is reasonable to expect for the change of that property.
A method on the other hand may take any form, contain a simple or complex process, and change the state of the object in any way.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hello,
I am writing an interface and its implementation in C#. I want some events to be defined in implementation.
I want to know how to declare events in Interface???
for example the event defined in Implementation is
public delegate void OperatorBtInsertHandler();
public event OperatorBtInsertHandler OperatorBtInsertClicked;
public void OperatorBtinserted(string strAddress)
{
}
what i need to write in interface????
Gajesh
|
|
|
|
|
Hi!
event OperatorBtInsertHandler OperatorBtInsertClicked; will do.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi,
I'm making a hotkey app and don't know how to know which hotkey has been pressed. Here's the relevant part of my source:
My hotkey class
class Hotkey : IMessageFilter
{
[DllImport("user32.dll", SetLastError = true)]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
private const int WMHotkey = 0x0312;
#region Properties
private IntPtr _Handle;
public IntPtr Handle
{
get { return _Handle; }
set { _Handle = value; }
}
private int _Key;
public int Key
{
get { return _Key; }
set
{
UnregisterHotkey();
try
{
RegisterHotKey(value, _Mod);
}
catch (Exception e)
{
MessageBox.Show("Could not register Hotkey - there is probably a conflict. " + "/br " + e.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_Key = value;
}
}
private byte _Mod;
public byte Mod
{
get { return _Mod; }
set
{
UnregisterHotkey();
try
{
RegisterHotKey(Key, value);
}
catch (Exception e)
{
MessageBox.Show("Could not register Hotkey - there is probably a conflict. " + "/br " + e.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_Mod = value;
}
}
private bool _isPressed;
public bool isPressed
{
get { return _isPressed; }
set { _isPressed = value; }
}
#endregion
private event EventHandler HotkeyPressed;
public Hotkey(Keys key, byte modifier, EventHandler hotKeyPressed)
{
if (key != Keys.None)
{
HotkeyPressed = hotKeyPressed;
try
{
RegisterHotKey(CharCodeFromKeys(key), modifier);
}
catch (Exception e)
{
MessageBox.Show("Could not register Hotkey " + key.ToString() + " - there is probably a conflict. " + "/br " + e.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Application.AddMessageFilter(this);
}
}
public Hotkey(Keys key, Keys modifier, EventHandler hotKeyPressed)
{
if (key != Keys.None)
{
HotkeyPressed = hotKeyPressed;
try
{
RegisterHotKey(CharCodeFromKeys(key), ModifiersFromKeys(modifier));
}
catch (Exception e)
{
MessageBox.Show("Could not register Hotkey " + key.ToString() + " - there is probably a conflict. " + "/br " + e.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Application.AddMessageFilter(this);
}
}
public static byte CharCodeFromKeys(Keys k)
{
byte charCode = 0;
if ((k.ToString().Length == 1) || ((k.ToString().Length > 2) && (k.ToString()[1] == ',')))
charCode = (byte)k.ToString()[0];
else if ((k.ToString().Length > 3) && (k.ToString()[0] == 'D') && (k.ToString()[2] == ','))
charCode = (byte)k.ToString()[1];
return charCode;
}
private const byte ModAlt = 1, ModControl = 2, ModShift = 4, ModWin = 8;
public static byte ModifiersFromKeys(Keys k)
{
byte total = 0;
if (((int)k & (int)Keys.Shift) == (int)Keys.Shift)
total += ModShift;
if (((int)k & (int)Keys.Control) == (int)Keys.Control)
total += ModControl;
if (((int)k & (int)Keys.Alt) == (int)Keys.Alt)
total += ModAlt;
if (((int)k & (int)Keys.LWin) == (int)Keys.LWin)
total += ModWin;
return total;
}
~Hotkey()
{
Application.RemoveMessageFilter(this);
UnregisterHotKey(this._Handle, this.GetType().GetHashCode());
}
public void UnregisterHotkey()
{
Application.RemoveMessageFilter(this);
UnregisterHotKey(this._Handle, this.GetType().GetHashCode());
}
private void RegisterHotKey(int key, int modifier)
{
bool isKeyRegisterd = RegisterHotKey(this._Handle, this.GetType().GetHashCode(), modifier, key);
if (!isKeyRegisterd)
throw new ApplicationException("Hotkey already in use");
}
public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
case WMHotkey:
{
if ((int)m.LParam != 1114112)
{
isPressed = true;
HotkeyPressed(this, new EventArgs());
return true;
}
else
return false;
}
}
return false;
}
}
The class works fine for 1 hotkey but when I try and implement multiple instances of the class I can't tell which hotkey is pressed. For example:
<br />
Hotkeys[0] = new Hotkey(Properties.Settings.Default.Play, Properties.Settings.Default.PlayMod, OnHotkeyPressed);
Hotkeys[1] = new Hotkey(Properties.Settings.Default.Next, Properties.Settings.Default.NextMod, OnHotkeyPressed);
When I check the isPressed properties the Hotkeys[0](Play hotkey) isPressed property is always true and the Hotkeys[1] is always false(next hokey) even when that hotkey is pressed.
Also another problem I have is that I can only create a hotkey for the letters on the keyboard(keys A-Z) but not PageDown, the F1-F2 keys, the Arrow keys. Does anyone know a work around for this?
Can anyone help me with these problems
Thanks a lot
Luke Dyer
|
|
|
|
|
Hi,
the id parameter in RegisterHotkey must be unique (your _Mod is not good); it is used
internally to discriminate the different hotkeys; I once used the following code:
int chr=(int)name[0];
if (chr>=(int)'a' && chr<=(int)'z') chr+=(int)'A'-(int)'a';
int ident=GetType().GetHashCode()+(modifiers<<16)+chr;
but that is just one attempt to get unique numbers for some command based on its
name (some textual description) and the modifier keys (similar to Control.ModifierKeys)
all inside a form.
|
|
|
|
|
Hi
I am using Visual Studio 2005 and C# to develop a Windows application. I am trying to trigger a keypress or keydown event on the form.
When there are no other controls on the form it works well. Testing with the following:
private void Form1_KeyDown(object sender, KeyEventArgs e)<br />
{<br />
if (e.KeyCode == Keys.C)<br />
{<br />
<br />
}<br />
}
The moment I add another control onto the form, for example a Button, the KeyDown event does not fire anymore.
What am I missing here?
Thanks.
Kobus
|
|
|
|
|
Hi,
part of the GUI job is to dispatch events to the appropriate Control.
If you want your Form to also get keyboard events even when one of its Controls has focus,
look at Form.KeyPreview property.
|
|
|
|