|
Zachery Hysong wrote: the concept of having to write `ref` twice seems counterintuitive to me. The first time (in the method declaration) you use it to explain to the compiler that you're passing the string by reference, not as a value.
The second could be omitted if the language would allow it; it doesn't because it helps to determine what is being passed. If you read the call to the method, then without the additional "ref" keyword it'd be impossible to say whether it is passed as a value or a reference without looking up the method-signature.
It also prevents mistakes; you can never pass in a value by "mistake"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Look at the code:
public void optionCheck(TextBox txt, string str)
That means that both txt and str are Value parameters - the default - which means that the value of the variable is copied and the copy passed to the method when it is called - so any changes to the value of the variable affect the copy, and not the original. When the method ends, the modified value is thrown away.
This is exactly the normal behaviour - and it is exactly what you want to happen!
Take an example, and think about what would happen if what you expected to happen did:
public void Change(int i)
{
i = i + 2;
} Now, that's fine when you call it like this:
int iOriginal = 6;
Change(iOriginal);
Console.WriteLine(iOriginal); You will be expecting to get "8" printed.
But...what happens if you do this:
Change(6);
Console.WriteLine(6); The last thing you want is to get "8" printed!
But that is exactly what "should" happen - you passed in a value, the method changed it and tit affected the outside world. The method doesn't know - and can't check - that you are passing in a value that can be variable!
You can do what you want, but you have to tell teh system that that is exactly what you want to happen:
public void optionCheck(TextBox txt, ref string str)
{
if (txt.Text == "0")
{
str = "+++";
}
else
{
str = "---";
}
} And call it like this:
optionCheck(txtDoorsSafety1, ref strDoorsOption1); But then you can't call it with a string constant because will get a compilation error, and the system now knows you want to change a constant, and you can't do that!
Make sense?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Yes, and this is one of the best explanations ever. Thank you.
|
|
|
|
|
You're welcome!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
You're passing the parameter by value, which means that any changes you make to the parameter within the method will be discarded when the method returns. I suspect you meant to pass it by reference, so that the changes would be copied back.
Passing Parameters (C# Programming Guide)[^]
In this case, since you're not using the value of the parameter within the method, and you're always assigning a value to it before the method returns, you should declare it as an out parameter.
public void optionCheck(TextBox txt, out string str)
{
if (txt.Text == "0")
{
str = "+++";
}
else
{
str = "---";
}
}
optionCheck(txtDoorsSafety1, out strDoorsOption1);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
The groups of the local machine, or of the domain? Execute below command on a console, see if it returns what you want;
C:\> NET GROUP /DOMAIN
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
All the groups in the domain via code in c-sharp
foreach ( var group in user.Groups )
If I can get a list of groups from a single-user, why is getting a list of all groups so difficult.
I want to create a form and have a property user-groups.
If the user is in one of the groups, he can view the form.
To fill the list of groups that can be assigned to the form, I need a list of all groups.
|
|
|
|
|
sneezesnoeze wrote: via code in c-sharp Exeucte the command I showed using the Process-class, and read it's result. Or redirect the output to a file.
sneezesnoeze wrote: If I can get a list of groups from a single-user, why is getting a list of all groups so difficult. ..because the current user doesn't need to know all the groups that exist, just the ones he can access?
sneezesnoeze wrote: If the user is in one of the groups, he can view the form. Simple solution; don't show the ones he's not in.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
hmmm
I try to understand windows security but I can't really get my mind arround it.
I hoped to be able to get the list of groups via c#-code, not to start a separate process.
If it is neccesary, i wil do it but rather not.
As a programmer I am interrested in the full list. I am not the user, but I need to know which groups there are.
Before I can prevent showing the user a form that he is not allowed to see, I need to define which groups are allowed to see the form.
What should be the property type of form ?
|
|
|
|
|
sneezesnoeze wrote: I hoped to be able to get the list of groups via c#-code, not to start a separate process. Let me write a wrapper; why does it have to be C#-code?
sneezesnoeze wrote: but I need to know which groups there are. The user doesn't. One sees what one is allowed to see, not more.
sneezesnoeze wrote: Before I can prevent showing the user a form that he is not allowed to see, I need to define which groups are allowed to see the form. No; you only show the user what he is allowed to see. That's how banks work; they show your bank-accounts, as opposed to listing ALL accounts and disabling the ones that aren't yours. Moreover, what would an end-user do with things he can't access? Why is it so important to show bank-accounts that I cannot access? Would I, as a user, not rather not see them at all?
There's an example that does what you want (with C# code) here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Well, the obvious way to do this would seem to be to use the AD services functionality to search the domain. Off the top of my head, it would look a little bit like this:
PrincipalContext context = new PrincipalContext(ContextType.Domain);
GroupPrincipal principal = new GroupPrincipal(context, "*");
PrincipalSearcher searcher = new PrincipalSearcher(principal);
foreach (var group in searcher.FindAll())
{
Console.WriteLine(group.DistinguishedName);
}
|
|
|
|
|
Well,
try this function :
static public void directoryInfo()
{
var di = new DirectoryInfo(@"\\server\shared\Alignment_Meeting");
foreach (DirectoryInfo dir in di.GetDirectories())
{
Console.Write(dir.FullName + "\n");
DirectorySecurity ds = dir.GetAccessControl(AccessControlSections.Access);
foreach (FileSystemAccessRule fsar in ds.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)))
{
string userName = fsar.IdentityReference.Value;
string userRights = fsar.FileSystemRights.ToString();
string userAccessType = fsar.AccessControlType.ToString();
string ruleSource = fsar.IsInherited ? "Inherited" : "Explicit";
string rulePropagation = fsar.PropagationFlags.ToString();
string ruleInheritance = fsar.InheritanceFlags.ToString();
Console.Write(userName + " : " + userAccessType + " : " + userRights + " : " + ruleSource + " : " + rulePropagation + " : " + ruleInheritance + "<br/>");
}
}
}
Yonatan Arbel -
|
|
|
|
|
Use one of the System.DirectoryServices[^] namespaces. The syntax and functionality will be dependent on the one that you choose. I prefer S.DS.P as it doesn't go through ADSI and is faster, but vanilla S.DS and S.DS.AM are more commonly used, and have a wealth of information on usage available.
|
|
|
|
|
Hi All,
Please Let me know the best wind forms controls which have the best performance and support Right-To-Left languages.
I try Telerik which support Right-To-Left but the performance is not good, and I try Infragisitcs does not support Right-To-Left.
Please help me ASAP to know whcih controls I will use.
Thank you All
|
|
|
|
|
zead wrote: Please help me ASAP We're volunteers, and the answers are free. You can't rush that.
You could try the other major vendors, like DevExpress - either download a trial or ask a salesperson whether it is supported.
The best performance would be by using the native controls (as they are out of the box). That would also be the one that adheres the default best, and -best of all-, they're free.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Telerik and Devexpress are the two major providers, I used both in my projects. I am very sure that Devexpress supports localization and right-to left support. Please try the following link,
https://documentation.devexpress.com/#AspNet/CustomDocument8925[^]
I strongly recommend you to try the Devexpress. The localization and right to left support provided by DevExpress web control is better that what Telerik provides(though I prefer Telerik in general).
|
|
|
|
|
Hi!
How to save the RenderTargetBitmap to png?
there is my code. No error But the file doesn't create.
private async Task<bool> SaveImageAsync(StorageFile file)
{
try
{
using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
RenderTargetBitmap renderer = new RenderTargetBitmap();
await renderer.RenderAsync(SavedPic, (int)SavedPic.Width, (int)SavedPic.Height);
var buffer = await renderer.GetPixelsAsync();
stream.Seek(0);
await stream.WriteAsync(buffer);
await stream.FlushAsync();
}
}
catch
{
return false;
}
return true;
}
modified 16-Jun-14 5:25am.
|
|
|
|
|
There won't be an error because you're catching everything and binning it. I guess the task returns false, but you probably don't check that and even if you do, you've thrown away the information in the exception.
A catch that does nothing with the exception is generally bad practice because it makes it hard to work out what is going wrong. At minimum, you should drop the exception message and trace into a log file; in this case you should put up an error UI of some kind because this code should not fail and the user will want to know when it does.
|
|
|
|
|
it's return true. i sure that. 
|
|
|
|
|
hi
i want to develop a mini messaenger in xmpp with conversation tabpage, Emotion panel.
i can duplicate tabpage by clicking " Add " button in my form. when i duplicate 2,or ... tabpage . and when i click show panel, panel dont visible in my current tabpage and visible in other tabpage(in last tabpage), i uploaded my project :
http://www.megafileupload.com/en/file/541739/tabpage-rar.html[^]
help me to slove problem
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace tabpage
{
public partial class Form1 : Form
{
private System.Windows.Forms.Panel pan;
private System.Windows.Forms.Button bt;
private System.Windows.Forms.PictureBox im1;
private System.Windows.Forms.PictureBox im2;
private System.Windows.Forms.PictureBox im3;
private System.Windows.Forms.TabPage tp;
public Form1()
{
InitializeComponent();
}
private void duplicate()
{
this.pan = new System.Windows.Forms.Panel();
this.bt = new System.Windows.Forms.Button();
this.im1 = new System.Windows.Forms.PictureBox();
this.im2 = new System.Windows.Forms.PictureBox();
this.im3 = new System.Windows.Forms.PictureBox();
this.tp = new System.Windows.Forms.TabPage();
pan.Location = new Point(201, 6);
pan.Size = new Size(140, 146);
pan.BackColor = Color.Gray;
pan.Visible = false;
bt.Location = new Point(235, 158);
bt.Text = "show";
this.bt.Click += new System.EventHandler(this.bt_Click);
im1.Size = new Size(25, 25);
im1.Location = new Point(3, 3);
im1.Image = Properties.Resources._16_circle_green;
im1.SizeMode = PictureBoxSizeMode.CenterImage;
im2.Size = new Size(25, 25);
im2.Location = new Point(30, 3);
im2.Image = Properties.Resources.delete__166_;
im2.SizeMode = PictureBoxSizeMode.CenterImage;
im3.Size = new Size(25, 25);
im3.Location = new Point(57, 3);
im3.Image = Properties.Resources.down;
im3.SizeMode = PictureBoxSizeMode.CenterImage;
tp.Controls.Add(pan);
tp.Controls.Add(bt);
pan.Controls.Add(im1);
pan.Controls.Add(im2);
pan.Controls.Add(im3);
tabControl1.Controls.Add(tp);
}
private void bt_Click(object sender, System.EventArgs e)
{
if (bt.Text == "show")
{
pan.Visible = true;
bt.Text = "hide";
}
else if (bt.Text == "hide")
{
pan.Visible = false;
bt.Text = "show";
}
}
private void button1_Click(object sender, EventArgs e)
{
duplicate();
}
}
}
http:
modified 15-Jun-14 5:25am.
|
|
|
|
|
Don't post the same thing in multiple places: it wastes time and annoys people.
You have this in QA, leave it there.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
namespace AddItemInComboBox
{
public partial class Form1 : Form
{
const string conString = "Data Source=ABHINANDANCOMPU;Initial Catalog=Color;Integrated Security=True";
public SqlConnection con = new SqlConnection(conString);
public SqlDataAdapter da = new SqlDataAdapter();
public DataSet ds = new DataSet();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cmbCompany.DataSource = null;
ComboBoxAddData("companyName", "companyId");
}
private void ComboBoxAddData(string DisplayMember, string ValueMember)
{
cmbCompany.DataSource = null;
cmbCompany.Items.Clear();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("SELECT [companyId],[companyName] FROM tblMasterCompany", con);
con.Open();
da = new SqlDataAdapter(cmd);
da.Fill(ds, "tblMasterCompany");
cmbCompany.DataSource = ds.Tables["tblMasterCompany"];
this.cmbCompany.ValueMember = "companyId";
MessageBox.Show("Add SuccessFully");
da.Dispose();
con.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO tblMasterCompany ([companyName] ,[address] ,[city]) VALUES ('" + txtCompanyName.Text + "', '" + txtAddress.Text + "', '" + txtCity.Text + "')", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Save ");
con.Close();
Form1_Load(sender, e);
}
}
}
modified 15-Jun-14 3:39am.
|
|
|
|
|
First off, format that code so we can tell what is going on: edit the question, ands use <pre>...</pre> tags round it to preserve the formatting.
Then try explaining in more detail in the question itself what you are doing to cause the problem and what effects it is having: Remember that we can't see your screen, access your HDD, or read your mind!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
sir i want refresh list in combo box after create a new item
|
|
|
|
|