|
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
|
|
|
|
|
thanks a lot everybody for the responses..
will do evrything what is required to crack it...
|
|
|
|
|
I think code "ts.Days/365" is not right,leap year should be considered
|
|
|
|
|
hi all..have found the solution to the problem above posted by me..thxx evryone fr their suggestions..will post the answer sometime...
|
|
|
|
|
Hey Guys,
Quick question, I need to find TrackBar's Scroll Box/thumb/slider position in pixels. I need to put a ToolTip on
Workaround:- I can get it by doing some math on TrackBar.value
Is there any better way?
Thanks in Advance... 
|
|
|
|
|
There is no direct way to do it - math is all you have, but it's not too complex.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
I am trying to draw lines using below code
graphic.DrawLines(new Pen(Color.Red), pointarray);
pointarray size is 3852, I am getting overflow exception, Is there any limit to pass pointarray in DrawLines method.
Please describe...
|
|
|
|
|
Offhand, you could check if all the values are appropriate - maybe one of the values in the array are incorrect.
|
|
|
|
|
|
No, there is no limit I am aware of, and a quick test says that you can use more than 3852 points anyway:
Point[] points = new Point[4096];
public frmTesting()
{
InitializeComponent();
Random r = new Random();
for (int i = 0; i < points.Length; i++)
{
points[i] = new Point(r.Next(0, 200), r.Next(0, 200));
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Pen p = Pens.Red;
e.Graphics.DrawLines(p, points);
}
Works with no problems. I would suspect the problem is in your other code.
BTW: You shouldn't create a new Pen like that - you are responsible for calling Dispose on all graphics elements you create, so you should keep a reference to it, or use a stock item as I did.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
The only limits I know of are the size of the array you're passing. It must be less than 2GB of data and be less than Int32.MaxValue (2.147 billion) elements long.
|
|
|
|
|
I received a C# 2008 console application from a contract shop to work with. The purpose of the console application is to consume data it receives from a web service. (The contract shop that wrote the web service also wrote the console application I am suppose to work with.)
My questions are the following:
1. The console application writes to a log file. The only results I can see that can come from the log file is a dos window that displays while the application is running. If this is true, can you tell me how to have the log file write to a different location?
2. When I run the console application, I sometimes see error messages that show up in the dos popup window. At first I thought the error messages came from the web service. However today I opened up an *.xsd file and I see alot of the error messages that appeared in the dos window the last few days. Thus can you tell me how to determine how the *.xsd file is wired to the application? I would like to learn how the code is called.
3. Can I step through the code that is executed from the *.xsd file? If so, how would I accomplish this task? Do I need certain debug options set?
|
|
|
|