|
How to set default textbox value in C#.net
|
|
|
|
|
What do you mean by the default textbox value? If it's just a value when the form displays, simply set the Text property as in userName.Text = "No user"; . Is it something more complicated that you are after?
|
|
|
|
|
sir, i'm using textbox in my project having calculating some value.
Noe if user hv'nt entered any value, then I wish to set default value as "0".
plz suggest me something.
|
|
|
|
|
Check if the user entered a value when the textbox looses focus. If not, set aforementioned property to '0'.
If this sounds "complex", then you probably want to spend some time at the library with a good book on the subject.
Bastard Programmer from Hell
|
|
|
|
|
Use the Properties window to set the 'Text' property to 0. This could be set as default when your form initializes. When the textbox loses focus add a validation. This should suffice. Alternatively I suppose you can set the text box to accept numbers only.
Sunil
|
|
|
|
|
Hi am using one dll in my application.
it is used to show popup for login.
In this popup there is a link for Change Password and Reset Password, but a method for this link is declared in internal class in that dll file.
This is the internal class in that dll.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace Satis.Client
{
internal class AuthenticationForm : Form
{
private string _resetPasswordUrl;
private string _changePasswordUrl;
private string _application;
public string ResetPasswordUrl
{
set
{
this._resetPasswordUrl = value;
}
}
public string ChangePasswordUrl
{
set
{
this._changePasswordUrl = value;
}
}
public string Application
{
set
{
this._application = value;
}
}
private void _changePasswordLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (!string.IsNullOrEmpty(this._changePasswordUrl))
{
Process.Start(this._changePasswordUrl);
}
}
private void _resetPasswordLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (!string.IsNullOrEmpty(this._resetPasswordUrl))
{
Process.Start(this._resetPasswordUrl);
}
}
}
Here i can able to pass the value to this properties in AuthenticationForm class, but when i click on those link, it is not firing the event and this links are not opening,
Please find my code below.
public class RTFEauthentication
{
IAuthentication wrapper;
string ChangePwd = "http://gmail.com";
string ResetPwd = "http://microsoft.com";
string appName = "LRM";
public RTFEauthentication()
{
wrapper = new Authentication("*****************", "LRM", "UAT", "AUTH", "1.7.3", null);
Authentication.ChangePasswordUrl = ChangePwd;
Authentication.ResetPasswordUrl = ResetPwd;
}
public string ChangePasswordURL
{
get
{
return ChangePwd;
}
}
public string ResetPasswordURL
{
get
{
return ResetPwd;
}
}
public string Application
{
get
{
return appName;
}
}
public bool ValidateRTFE()
{
object formInstance = PrivateMethodAccessHelper.GetInstanceOfClass("Satis.Client",
"Satis.Client.AuthenticationForm", new object[] { });
PrivateMethodAccessHelper.SetInstancePropertyValue(formInstance.GetType(),
"ChangePasswordUrl", formInstance, ChangePasswordURL);
PrivateMethodAccessHelper.SetInstancePropertyValue(formInstance.GetType(),
"ResetPasswordUrl", formInstance, ResetPasswordURL);
PrivateMethodAccessHelper.SetInstancePropertyValue(formInstance.GetType(),
"Application", formInstance, Application);
PrivateMethodAccessHelper.SetInstanceFieldValue(wrapper.GetType(),
"_form", wrapper, formInstance);
IAuthenticationResult result = wrapper.AuthenticatePopup();
if (result == null)
return false;
else
return result.Succeeded;
}
}
public sealed class PrivateMethodAccessHelper
{
public static object GetInstanceOfClass(string assembly,
string fullyQualifiedName, params object[] contructorParams)
{
return Activator.CreateInstance(Type.GetType(fullyQualifiedName + "," + assembly), contructorParams);
}
/// <summary>
/// Set value of the object member.
/// </summary>
public static void SetInstancePropertyValue(Type typ, string propName, object objInstance, object objValue)
{
PropertyInfo propInfo = typ.GetProperty(propName, BindingFlags.Default | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (propInfo != null)
{
propInfo.SetValue(objInstance, objValue, null);
}
}
/// <summary>
/// Set value of the object member.
/// </summary>
public static void SetInstanceFieldValue(Type typ, string fieldName, object objInstance, object objValue)
{
FieldInfo fieldInfo = typ.GetField(fieldName, BindingFlags.Default | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (fieldInfo != null)
{
fieldInfo.SetValue(objInstance, objValue);
}
}
}
Could any one pls tell me what is the problem here and how to fix it.?
|
|
|
|
|
If you own this class (and the fact that you have the source strongly implies that you do), make the class you want to use outside the assembly public! Internal means internal and using reflection hackery to get around that shows that you have a serious design problem.
Nothing happens because you haven't actually done anything with the form you create. If you hadn't obfuscated everything with the reflection crap then you'd have been able to spot that.
|
|
|
|
|
Hi Bob,
No, i dont own this class, this class available only that assembly and i have to display an webpage when that linkbutton in this internal class is clicked.
But if i directly invoke that method, i can able to display the url i want(see the code below), but if i pass the value into those 2 public properties, this url is not invoked when i click on those links in the popup.
formInstance.GetType().InvokeMember("_changePasswordLinkLabel_LinkClicked", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, formInstance, new object[] { null, null });
So could you tell me how to fix this.
|
|
|
|
|
I hate quote myself but really:
"Nothing happens because you haven't actually done anything with the form you create. If you hadn't obfuscated everything with the reflection crap then you'd have been able to spot that."
... I already pointed out the problem. Assigning properties does nothing, you have to actually use the form in some way (adding it as a control? not sure how ASP.net works exactly and this is definitely a bit of an abuse).
|
|
|
|
|
this popup form is used to check the user credentials, it is linked to some internal assembly and check the username and password which i eneter in this popup with the some internal assembly.
All the control in this form is working properly apart from those 2 link button.
|
|
|
|
|
Then there's something you aren't showing us, because nowhere in what you posted do you actually call a method on an instance of that class.
|
|
|
|
|
Could you explain a bit more in detail what you're trying to achieve? As it looks, you're trying to hook into some internal class to get at a username/password.
How would you need that to redirect a button? And who is "Satis"?
Bastard Programmer from Hell
|
|
|
|
|
Hi Eddy,
thanks for the respnse.
here, am passing the value into ChangePasswordUrl and ResetPasswordUrl property where it assign the value into _changePasswordUrl and _resetPasswordUrl this fields.
You can see that when this method
_changePasswordLinkLabel_LinkClicked is invoked it reads the data from _changePasswordUrl and open the link which i pass into this field.
Satis.Client is assembly/dll name which am consuming in my application.
|
|
|
|
|
Rocky23 wrote: here, am passing the value into ChangePasswordUrl and ResetPasswordUrl property where it assign the value into _changePasswordUrl and _resetPasswordUrl this fields.
I've seen the write-only properties in the first post - but no events that "should" get fired. I've also seen that you're trying to assign a value to a read-only property.
Rocky23 wrote: Satis.Client is assembly/dll name which am consuming in my application.
That much I figured. I also know it's a forms-application, and that you're trying to use one of their classes - and apparently, they're not documented. So, you found a way to create their form, and now you want it to point "elsewhere".
Now, from my point of view, you're trying to hook into someones authentication-mechanism.
Bastard Programmer from Hell
|
|
|
|
|
Hi codeproject world!
I wanna to have something like "desktop composition in windows 7" form my forms.
I have one main form and all other are mdi for that.
Thanks a lot.
|
|
|
|
|
There are a few things here:
1) You forgot to ask a question.
2) You need to explain what 'something like "desktop composition in windows 7" form' means in this context.
3) You need to ask a question
4) You need to explain what you have done, and where you have a problem.
5) You neglected to ask any question.
Oh, and in case I forgot to mention it - you need to ask a question if you want us to help.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
BTW: You forgot to ask a question.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi codeproject world!
I wanna to have something like "desktop composition in windows 7" form my forms.
I have one main form and all other are mdi for that.
Thanks a lot.
maybe you can get it here 
|
|
|
|
|
I thought to Google your "question" and it came up with this[^], so I guess you are interested in an "Aero" like them for your form. This is certainly possible and I would expect it requires you to make dynamic changes to the properties of each child window as you move the mouse around your form. Look at the Opacity property of your forms.
|
|
|
|
|
Sorry,
I wanna to have something like bellow:
when u press winKey + Tab in windows 7 you can change between Programs that are open .(the one same as Alt+Tab but very graphically)
|
|
|
|
|
One of these[^] may already provide what you want. If not then choose a key combination not already allocated and write a handler for it that switches between the MDI windows.
[edit]
Doing it graphically requires considerably more work and would probably be easier in WPF than pure C#; I hope your skills are up to it.
[/edit]
|
|
|
|
|
You can use Control.DrawToBitmap[^] to draw a copy of what's currently visible on a form or panel into an image, and then use image transformation (rotate/scale/skew) and drawing capabilities in the Graphics class to make a perspective-distorted version of it to scroll through.
Make sure you support the standard ways to navigate around an MDI form as well. This might seem like the coolest thing ever to you right now but users will probably want to switch in the way they always have.
|
|
|
|
|
I wanna this :
Windows Logo+TAB: Cycle through programs on the taskbar by using Aero Flip 3-D
for my Forms that are mdi.
should i use/find dll for that ?
modified 25-Jun-12 23:58pm.
|
|
|
|
|
Hi every one,
I have a small project to monitor the heart rate using c#.NET. I wrote a code to receive the ascii data using serial port through a bluetooth link between the pc and a Zephyr HxM device. What I need is how to convert this received ascii data into a decimal. The data consists of 64 bytes recieved every one second and I need from these data only byte number 12 which gives me the heart rate. So my question is how to receive the ascii code and select only byte no. 12 after convert the data
from ascii to decimal. Thanks for yur help.
|
|
|
|
|
That is a bit confusing. How is the information encoded for transmission? if it is in binary, you may not need a conversion at all. And if it is textual (say in ASCII), then you are likely to need more than one character (and hence more than one byte) to represent a heart rate.
I suggest you show us an example input (actual data!) and the relevant part of the code you have so far to receive the data from the serial port.
|
|
|
|