|
The 'trouble' with the WinForms 'TextBox' 'TextChanged' Event is that it doesn't give you much information: its 'event argument' is just a dumb old 'EventArgs.
If you use the 'Leave event of the TextBox to judge the user is done, imho that's an 'ambiguous' choice that can lead to confusion, since all it means is the user shifted focus to some other control or object.
A TextBox with its 'MultiLine' property set to 'false, will ignore Enter/Return key-presses, and the focus will stay in the TextControl. The properties 'AcceptsTab, and 'AcceptsReturn only apply to MultiLine = 'true TextBoxes.
A Tab entry is going to move the focus to the next control in the tab-order; again, imho, an unsatisfactory way to handle the need to know the user has finished doing whatever they want to do with a TextBox.
The KeyPress, KeyDown, and KeyUp events give you access easily to which key is pressed.
So, what to do ? Since it is something of a convention that hitting the 'Enter key means you are 'done' with something, why not use that:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
{
}
} Another idea I would consider, if dealing with users who were not 'socialized' to 'enter key = done' ... would be to make a UserControl that would be a combination of a CheckBox and a TextBox.
good luck, Bill
"Is it a fact - or have I dreamt it - that, by means of electricity, the world of matter has become a great nerve, vibrating thousands of miles in a breathless point of time? Rather, the round globe is a vast head, a brain, instinct with intelligence!" - Nathanial Hawthorne, House of the Seven Gables
|
|
|
|
|
The Observer Patterns provides more flexibility to handle events when compared to the Proxy Patterns?
Thanks for the help and attention...
|
|
|
|
|
Of course it does as the Proxy Pattern has absolutely sod all to do with events. Did you even read the answer below?
|
|
|
|
|
What's the difference between Proxy Patterns and Observer Patterns? and the observer provides more flexibility to handle events when compared to the Proxy?
Thanks for the help and attention...
|
|
|
|
|
A Proxy pattern is essentially a class representing an interface to something else.
Observer pattern is where an object notifies all its listeners whenever it changes.
So both are very different patterns used for different tasks, and cannot really be compared.
Search more on the internet, you will get samples and lots of code for these patterns.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
Can you tell me what is wrong with this code?
In an exisitng C#.net 2008 desktop application, I want to setup a class .cs file so I can do security checks against the active directory. I want to add this code to a project file that contains lots of common routines all the other processing modules use. The code is the following:
using System;
using System.Reflection;
using System.Runtime.Remoting;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using System.Security.Principal;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace En.Common
{
class ActiveDirectory
{
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
//Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
//if ((!Thread.CurrentPrincipal.IsInRole("testit")))
}
}
I want to start with 3 lines of code listed so far. However, the statement,
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
However I am getting the following two errors on this statement:
Error 94 Invalid token '(' in class, struct, or interface member declaration
Error 95 Invalid token ')' in class, struct, or interface member declaration
|
|
|
|
|
You need to put your statements into a method or constructor. At the moment it is like you are declaring then as class level variables.
Next time please put your code into Code Blocks. It makes it much easier to read!
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
I've created a custom control with a non-rectangluar border.
I'm trying to set the region properly and struggling to get a *filled* region.
I can make it the outline of my control, but then you can't drag the control from the middle.
How do I *fill* a region?
|
|
|
|
|
The Region property should be set to a collection of closed subpaths. Use the GraphicsPath methods to add a closed shape (e.g. AddPolygon, AddEllipse etc) or call CloseFigure for each subpath.
E.g. a circular control:
private void AdjustRegion()
{
GraphicsPath path = new GraphicsPath();
path.AddEllipse(-(Size * 0.5f) - 2, -(Size * 0.5f) - 2, Size + 4, Size + 4);
this.Region = new Region(path);
}
|
|
|
|
|
mmm, I've got a series of lines added to a Path, and I do then call CloseFigure. But the region is *just* those lines, not the space enclosed by them.
Even if I add a rectangle to the path, its just the rectangles edge that gets added, not the area covered by it.
|
|
|
|
|
Are you assigning Region (property) to a new Region object like in my example?
I took that from a (more complex) working example in real code so it definitely works.
|
|
|
|
|
Yep, tis the same assignment...and I've got it working in another project as well...just have to keep looking.
|
|
|
|
|
Hi,
I have created a program e.g. test.exe by C#.net and I want to
associate file extension (eg .tst) with the test.exe in the window registry.
But I found that most commercial program specifying file type in window registry by CLSID, (so the file type may be opened by the program for the dll specifid by the CLSID) which is only for dll. I have only an exe and I can specify opening the file type in the open subKey in the registry. But how can I specify the file type with a dll(CLSID) which in my case I dont have ?
or how can I convert my exe into dll so I can open the file type by the dll ?
Thanks
|
|
|
|
|
This isn't really a C# question.
File associations are stored in HKEY_CLASSES_ROOT/.ext. Most file types then have an almost empty key with the default value pointing to another key (typically 'extfile'). In that key, the default value is the friendly name for the type (appears in Windows Explorer and the File Types dialog). To associate the file type with a program, create a subkey Shell/open/command and for the default value in there, put the command to run (typically something like path/myapp.exe "%1" ).
|
|
|
|
|
Have done somethingg similiar. In the code below the file extension to be opened by the app is .stockcheckdata . This extension then needs to be associated with app, in my example the one being opened.
Registry.ClassesRoot.CreateSubKey(".stockcheckdata").SetValue("", "stockcheckdata", RegistryValueKind.String);
Registry.ClassesRoot.CreateSubKey(@"stockcheckdata\shell\open\command").SetValue("", Application.ExecutablePath + " \" %1 \"", RegistryValueKind.String);
Hope it helps?!
|
|
|
|
|
Try double-clicking the file and then tell Windows which app to use to open it.
|
|
|
|
|
Hi
I have a code in c# to read data in excelsheet.
string connstr = "provider = Microsoft.Jet.Oledb.4.0;Data Source='C:\\aaa.xls';Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(connstr);
string strSQL = "SELECT * FROM [Sheet1$]";
OleDbCommand cmd = new OleDbCommand(strSQL, conn);
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
dt = ds.Tables[0];
While reading i could not get few values in a particular column(say column B) and the values that are not being read are completely numeric(12345) while the others are alpha numeric(Ex: e0345) in the same column.
Example
Column B in excel has values as below
U098ij
i097hl
123453
gdtr56
When i see in the dataset, 3rd value is null. Dont know where i am going wrong. Please help me
Thanks in advance
Naina
Naina
|
|
|
|
|
There is a universal problem when accessing excel through ADO and that is that ADO only scans the first 8 lines and then chooses what data type to return based on the data type of the majority of the returned results. Thus if the majority of the returned results are strings, then it thinks that all the data should be returned as strings, and ignores other data types. The best way to get around this is to add the instruction IMEX=1 to the extended properties instruction in the connection string. Thus your connection string would now look like this:
string connstr = @"provider = Microsoft.Jet.Oledb.4.0;Data Source='aaa.xls';Extended Properties='Excel 8.0;IMEX=1'";
Of course, the problem with this is that all your data is returned as a string, and numeric values will need to be parsed.
Hope this helps
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
Wayne
Does this force large numbers into e##### format when converting to strings?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yes, unfortunately it does do this if you have the cell format set to general or number. This can lead to a serious loss of data. If you format the cells to currency or accounting, then you get the actual value.
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
Hi
Thanks for your reply and now i have included IMEX to extended properties. Now the problem is, large numbers are converted into e**** format
Regards
Naina
Naina
|
|
|
|
|
Hi, please read my answer to Mycroft above. The only solution is to format your cells as accounting or currency.
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
Hello,
I made an application with clients who connect to a server with .Net remoting. The client requests some values from the server and then the server putts all these request in a buffer (buffer is necessary) and emptys them each 500ms, these requests are send to a "black box" on a socket connection, and then the answer of the black box is being send back to the client with an eventhandler.
Now I have something like
remoteServer.GetValue(Name);
which is given back to the client in an event
But what I want is getting something like this.
Int32 receivedVal = (Int32)remoteServer.GetValue(Name);
Does anyone know the solution?
Thank you
|
|
|
|
|
My suggestion may not be usable by you:
First get rid of remoting services and deploy your service as a WCF service.
Second make sure your WCF service is NOT deployed as Asynchronous.
Third pull the 'black box' into your service so make it a class that you can instantiate and call internally.
When your service gets the answer back then return it.
In the WCF service your service would be written as if it was an inline method call making the setup quite simple. It also gets rid of the buffering and polling.
If you cannot get rid of the black box behaviour then you might be SOL.
Software Zen: delete this;
|
|
|
|
|
My goal is to try to use the same logic when verifying groups in the active directory for users if they are on the web or in a windows application. However my current problem is the web application is currently using a config file and having users enter their user name and password. The windows application is having the user click on a desktop shortcut and the application obtains the user infromation from windows authenication.
Is there a way to make code listed in the windows application be more like the web application?
If not,why not?
If so, how would you change the code to make to the windows application?
The windows code is the following:
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
hread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if ((!Thread.CurrentPrincipal.IsInRole("TEST"))
{
MessageBox.Show("Please contact your network administrator if you have any questions",MessageBoxIcon.Error);
return;
}
else
{
Application.Run(new newm());
break;
}
The web code is the following:
using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
namespace RtSup
{
public class Validator
{
private string _path;
private string _filterAttribute;
public Validator(string path)
{
_path = path;
}
public bool IsAuthenticated(string domainName, string userName, string password)
{
string domainAndUsername = domainName + @"\" + userName;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, password);
try
{
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + userName + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if (null == result)
{
return false;
}
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return true;
}
}
}
|
|
|
|