|
I suspect you are asking why a string is a class rather than a structure, and there are many reasons for this. This[^] question gives a fairly detailed set of answers as to why a string is a class (and has to sit on the heap).
|
|
|
|
|
try this[^]
BTW, this is about one of the most basic things in programming. What's wrong with buying a good book and read?
V.
|
|
|
|
|
IMO that is the right answer.
|
|
|
|
|
|
Wikipedia is accurate. [citation needed]
|
|
|
|
|
Surprisingly, it is often very authoritative and accurate. Quite remarkable, actually, unless Dalak Dave is among the sources referenced.
Will Rogers never met me.
|
|
|
|
|
<pre>How you tell me how to change the C#.net desktop 2008 logic so it will compile clean and the logic works? The problem is I am trying to create an instance of an object in a static class
In this application I want to create a 'class with methods for accessing the active directory' from all parts of the solution file. As part of this logic change when a user clicks on the desktop shortcut and they are not assigned to any active directory groups, I want to throw an error message stating 'do not have access-contact network administrator and throw them out of the application.
The logic to check the user credentials comes from the main method that is a 'static' method in program.cs.
The code I want to add to the main methos is as follows:
ActiveDirectoryUser CurUser;
CurUser = new ActiveDirectoryUser();
However I get the following errors:
-
Error 55 'Desktop.CurUser': cannot declare instance members in a static class
Error 56 The type or namespace name 'ActiveDirectoryUser' could not be found (are you missing a using directive or an assembly reference?)
Error 57 The type or namespace name 'ActiveDirectoryUser' could not be found (are you missing a using directive or an assembly reference?)
The cLass i want to reference looks like the following:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Threading;
using System.Web;
using System.Windows.Forms;
using System.Security.Principal;
namespace EnrollTrac.Common
{
public class ActiveDirectoryUser
{
public ActiveDirectoryUser()
{
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if ((!Thread.CurrentPrincipal.IsInRole("testit")))
{
MessageBox.Show("You do not have authortity.Please contact your network administrator"," Error", essageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
Application.Run(new Desk());
break;
}
</pre>
|
|
|
|
|
dcof wrote: Error 56 The type or namespace name 'ActiveDirectoryUser' could not be found (are you missing a using directive or an assembly reference?)
"Add a new assembly reference to System.DirectoryServices.dll. This provides access to the System.DirectoryServices namespace that contains managed types to help with Active Directory querying and manipulation."
dcof wrote: Error 55 'Desktop.CurUser': cannot declare instance members in a static class
Mark it with the "static" keyword, if it's appropriate a
Bastard Programmer from Hell
|
|
|
|
|
Hi,
I have a textbox control with 2 buttons for different actions to perform.
Now, there is a check on this textbox, which I am initiating by using OnTextChanged method.
While this is initiated, I want the buttons to be greyed, otherwise this check is not complete till the user clicks on the screen again or clicks to the next textbox.
That way they cannot change some value and access the submit buttons without this method being completed.
Thanks.
|
|
|
|
|
Your description is extremely hard to understand.
Why don't you just disable the buttons if the text field is empty, and enable them in the textChanged event handler if the proper conditions are met.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I apologize for this.
But, I want an action to take place only if the text value has changed.
The problem is the onTextChanged method is not completed till the user clicks on the computer screen or tabs to the next textbox. If you are using a mouse, then you are not clicking anywhere on the screen and have the option to click on the button which should not happen.
|
|
|
|
|
vanikanc wrote: the onTextChanged method is not completed till the user clicks on the computer screen or tabs
That doesn't sound right. The TextChanged event fires on every change, right away, no special user action required. This code would prove that:
System.Windows.Forms.TextBox tb;
System.Windows.Forms.Label label;
public void Test() {
Form f=new Form();
tb=new TextBox();
tb.Bounds=new Rectangle(10,10,100,20);
f.Controls.Add(tb);
label=new System.Windows.Forms.Label();
label.Bounds=new Rectangle(10, 50, 100, 20);
f.Controls.Add(label);
tb.TextChanged+=new EventHandler(tb_TextChanged);
f.ShowDialog();
}
void tb_TextChanged(object sender, EventArgs e) {
label.Text=tb.Text;
}
|
|
|
|
|
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
|
|
|
|