|
Why can't you simply reverse the assignments you have?
login.ShowDialog();
username = login.Username;
password = login.Password;
etc....
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Create a property (or several) in the Form and read it back from the instance once ShowDialog returns - it won't until the user closes the form, so read the data at that point.
frmLogin login = new frmLogin();
login.Type = type;
login.Username = username;
login.Password = password;
login.Group = group;
login.ShowDialog();
type = login.Type;
username = login.Username;
password = login.Password;
group = login.Group;
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
What I did....
In Class 1
if (login.ShowDialog()== DialogResult.OK)
{
ans= login.Result;
}
In form 1
public int Result
{
get;
set;
}
Result = value;
this.DialogResult = DialogResult.OK;
Thnks a lot all,
Sai
|
|
|
|
|
That'll do it!
Nice one - well done.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I can't make any connection between the code you show here, and any other post on this thread:
This code is not going to compile:
1. the variable 'ans is never declared, or used, just assigned to; will not compile.
2. the variable 'value is never declared: Result = value; will not compile.
3. the statement: "this.DialogResult = DialogResult.OK;" makes no sense unless you have a Form1 scoped variable with the name 'DialogResult declared, and, you should not use variable names identical to Operator names since that way lies utter code confusion. And why would you need a Form1 scoped variable of this type in the first place ?
This is a case where posting code-fragments means no meaningful response is possible.
best, Bill
"If you shoot at mimes, should you use a silencer ?" Stephen Wright
|
|
|
|
|
It compiled and worked.
Thanks,
Sai
|
|
|
|
|
I have this XML file
<?xml version="1.0" encoding="utf-8"?>
<Contacts>
<Contact>
<ContactId>0</ContactId>
<Prefix>
</Prefix>
<FirstName>Kevin</FirstName>
<MiddleName>Marois</MiddleName>
<LastName>Brian</LastName>
<Suffix>
</Suffix>
<Birthday>1965-10-11</Birthday>
<Title>Senior Software Engineer</Title>
<Comments>has 25 years of development experience</Comments>
</Contact>
<Contact>
<ContactId>1</ContactId>
<Prefix>Dr.</Prefix>
<FirstName>Henry</FirstName>
<MiddleName>DeCarlo</MiddleName>
<LastName>G</LastName>
<Suffix>III</Suffix>
<Birthday>1965-10-11</Birthday>
<Title>Oral Surgeon</Title>
<Comments>His office is over on 23rd street</Comments>
</Contact>
<Contact>
<ContactId>2</ContactId>
<Prefix>
</Prefix>
<FirstName>Mattew</FirstName>
<MiddleName>Damon</MiddleName>
<LastName>Paige </LastName>
<Suffix>
</Suffix>
<Birthday>1970-10-08</Birthday>
<Title>Actor</Title>
<Comments>Excellent actor</Comments>
</Contact>
</Contacts>
I want to delete a contact using the ContactId. So far I have this:
public void DeleteContact(int ContactId)
{
ensureFileExists();
XmlDocument doc = new XmlDocument();
doc.Load(XMLFile);
var path = "/contacts/contact[ContactId=" + ContactId + "]";
XmlNode node = doc.SelectSingleNode(path);
node.ParentNode.RemoveChild(node);
doc.Save(XMLFile);
}
But the node is coming back null. How do I delete the contact? What's wrong here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Ahem... case sensitivity...
|
|
|
|
|
That did it. Thanks
If it's not broken, fix it until it is
|
|
|
|
|
And if that's your actual date of birth, then you're about two months older than me.
|
|
|
|
|
you catch it quickly so 5+
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
In my software i need to show the property dialog of a file and navigate to a specific tab in that property dialog? please tell me how to acheive this using c#?
or Is it possible to replace the default property dialog with a custom one?
|
|
|
|
|
Use the ShellExecuteEx Win32 API to achieve this.
using System.Runtime.InteropServices;
[DllImport("shell32.dll", CharSet = CharSet.Auto)]
static extern bool ShellExecuteEx(ref SHELLEXECUTEINFO lpExecInfo);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SHELLEXECUTEINFO
{
public int cbSize;
public uint fMask;
public IntPtr hwnd;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpVerb;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpFile;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpParameters;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpDirectory;
public int nShow;
public IntPtr hInstApp;
public IntPtr lpIDList;
[MarshalAs(UnmanagedType.LPTStr)]
public string lpClass;
public IntPtr hkeyClass;
public uint dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}
private const int SW_SHOW = 5;
private const uint SEE_MASK_INVOKEIDLIST = 12;
public bool ShowFilePropertiesDialog(string fileName)
{
SHELLEXECUTEINFO info = new SHELLEXECUTEINFO();
info.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(info);
info.lpFile = fileName;
info.lpVerb = "properties";
info.fMask = SEE_MASK_INVOKEIDLIST;
info.nShow = SW_SHOW;
return ShellExecuteEx(ref info);
}
And then use the method like this:
ShowFilePropertiesDialog(@"C:\hello.txt");
|
|
|
|
|
Thanks.but this would only display the property dialog, i need a way to navigate into one of tabs inside the property dialog.
|
|
|
|
|
How about using SendKeys[^] to send as many Control+Tab characters as required?
|
|
|
|
|
Hi,
I want to create a .Net Dll in c# which will have a GUI. I need to use this in a VB6 application. Is this possible?
I know how to create a class dll in C# and use it in VB6 also I can create an User Control in C# and used it in VB6 form.
What I want is the VB6 will call a dll (login screen) and the C# GUI will run and give back a yes/no result.
Thanks,
Sai
|
|
|
|
|
This[^] article discusses using .NET user control in VB6.
|
|
|
|
|
This is creating a user control. I figure it out. I had to add a form and call the form from the class.
Thanks,
Saimanti
|
|
|
|
|
Hi all,
AM working on a C# project..
my requirement is as follows:
there are 2 dates viz date1 & date2.
if date1 > date2
the difference should come as e.g (3years,2months)
if date1 < date2
the difference should come as e.g (-3years,-2months)
I am able to get the first scenario but the second scenario I am having problems with, not able to calculate the number of months in negative quite correctly...
Below is the code used in case of positive scenario,currentdate is alwys greater than the assetCapDate passed as a value:
public string newmethod(string assetCapDate)
{
string timeStr = string.Empty;
int years = 0;
int months = 0;
int days = 0;
TimeSpan ts = new TimeSpan();
System.DateTime date1 = DateTime.Now;
System.DateTime date2 = Convert.ToDateTime(assetCapDate);
ts = date1.Subtract(date2);
years = (ts.Days/365);
do
{
for(int i=0; i <= 12; i++)
{
if(date1.Subtract(date2.AddYears(years).AddMonths(i)).Days >=0)
{
months = i;
}
else
{
break;
}
}
if(months > 12)
years = years + 1;
}while(months > 12);
days = date1.Subtract(date2.AddYears(years).AddMonths(months)).Days;
if (years > 0)
{
timeStr += years.ToString() + " Years, ";
}
if (months > 0)
{
timeStr += months.ToString() + " Months";
}
if (days > 0)
{
timeStr += days.ToString() + " Days";
}
return(timeStr);
}
Any help would be highly appreciated.
I am not sure whether this question falls under C# domain..Moderators please advise accordingly..will move this question to another domain if required.
Regards
Anurag
|
|
|
|
|
Use the Math.Abs()[^] method to get the absolute value of the difference when converting to years and months.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
hi Richard..thxx for the suggestion..i did try Math.Abs stuff but still not getting the desired result...
The conversion into months in negative scenario is what I am not getting..
Further assistance would be highly appreciated..
Regards
Anurag
|
|
|
|
|
anurag3487 wrote: The conversion into months in negative scenario is what I am not getting. I'm not sure what you mean by this but using a TimeSpan object will get you the number of days difference, and using the Abs() method will get you the number as a positive integer. Converting that into months and years requires some logic which takes into account leap years and the number of days in each month, none of which is impossible, it just requires a little extra thought.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
The general way to get the difference between two DateTime values is just to subtract and get a TimeSpan. A TimeSpan only goes as high as Days, not months or years because doing so is rather difficult -- you must take the varying lengths of months and Leap Days and into account.
It were easy and reliable, it would be built-in. If you really want to do this, you're on your own. I seem to recall that someone else asked about this a few months back, but a quick search didn't turn it up.
|
|
|
|
|
PIEBALDconsult wrote: you must take the varying lengths of months and Leap Days and into account.
I'm not saying that it's right, or that anyone should do it, but what about the Datediff function in the Microsoft.VisualBasic namespace? There you'r able to get the difference in months and years without that hassle.
But saying that, I've not used that namespace in a C# solution.
|
|
|
|
|
See David Morton's answer on this[^] page.
/ravi
|
|
|
|