|
Apoll
The contructor is run when the a class is instantiated. A constructor has the same name as the class. In your code the constructor is
<br />
public Form1(){<br />
InitializeComponent();<br />
}<br />
What you will want to do is pass in the file name from the arguments list into this constructor. Modify the constructor to accept the path as a string like so:
<br />
public Form1(string ImagePath){<br />
InitializeComponent();<br />
}<br />
Then in the main method pass the path to the new form like so:
<br />
static void Main(string[] arguments)<br />
{<br />
Application.EnableVisualStyles();<br />
Application.SetCompatibleTextRenderingDefault(false);<br />
Application.Run(new Form1(arguments[0]));<br />
}<br />
I have assumed that the path is stored as the first item in the array.
You can then call the initialize method and pass in the path to the file (you will of course have to modify your initialize method to accept the file path as a parameter.
Hope this helps.
|
|
|
|
|
Ok, thank you very much, it is working.
Apoll
|
|
|
|
|
Be careful with that, because it REQUIRES at least one argument, and ignores all others. If you want to be able to run from the command line OR open the application through explorer, you need to either...
1. Send the entire argument array into the constructor, or
2. Put an if, else in your static main method to determine whether to call the initializer with parameters or without
If you only want this to run when you double click a file (or specify a file at the command line) then ignore this post.
Jeff
|
|
|
|
|
oh, yeprs, this is exactly my problem now.
The thing is, when I make it with if else like this:
public partial class Form1 : Form
{
Bitmap original_image;
string path;
public Form1(string[] ImagePath)
{
InitializeComponent();
if (ImagePath[0] != null)
{
path = ImagePath[0];
original_image = new Bitmap(path);
pictureBox1.Image = original_image;
}
}
it says that "if (ImagePath[0] != null)" is outside the bounds of the array
|
|
|
|
|
Just do this...
static class Program
{
[STAThread]
static void Main(string[] arguments)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1(arguments));
}
}
public partial class Form1 : Form
{
Bitmap m_Img null;
public Form1(string[] arguments)
{
InitializeComponent();
if (arguments != null)
{
foreach (string filePath in arguments)
{
if (File.Exists(filePath)) {
try {
m_Img = new Bitmap(filePath);
} catch {
// Do something if error reading file as bitmap
}
}
}
}
}
}
Jeff
|
|
|
|
|
Hey Jeff, you are great, now it is just as i wanted. Thank you very much for your help and your time.
Best regards
Alexander
|
|
|
|
|
Dear all,
I have a file which is on server.
Now I want to read this file's content for my application but I got the problem with providing username and password for accessing this file.
I can not find the above info in FileStream class.
Please tell me how I can do that.
Thanks in advance!
|
|
|
|
|
If your server is an HTTP or FTP server, you won't be able to do it with a file stream.
Instead, look at the WebRequest class. It has a Credentials property to provide username and password. It has a GetResponseStream which returns a Stream from which you can read the bytes, just like FileStream.
|
|
|
|
|
WebRequest ?
Can I do it with Window Form. My application is wind form.
Could you give me the explanation.
Thanks so much
|
|
|
|
|
If my computer connect to the server by Window Explorer, my application can read file normally.
But If I move application to another computer or restart my computer => Error.
I know that I must specify username and password to access to that computer for reading file but I do not know how to provide username and password for the operation.
Please help me to do that.
Thanks a lot.
|
|
|
|
|
I have done with reading file by using LogOnUser API function.
Thanks for your support.
|
|
|
|
|
Oh, you didn't mention the file is on a network share. Had you mentioned that, I could have pointed you in the right direction.
|
|
|
|
|
I have a custom control I'm building that has a custom drawing. However, I'm allowing the control to be moved around and I want to prevent the control from drawing itself because appareantly, when it does, it's drawing the transparent background and it's looking rather odd. I know in the old WinAPI 32 you could simple validate the invalid region and be done with it. Is there anything similiar to that in .NET?
|
|
|
|
|
I don't know about doing it the way you suggested, but you can override the OnPaint method and simply not call base.OnPaint when you want it to not do so. Does this help?
Jeff
|
|
|
|
|
Hi,
it's my first post here and I hope that someone can help me.
I'm developing an application in C#, using VisualStudio .NET 2005, which calls same functions from an ANSI C library.
My problems involve out of memory exceptions :S, because i don't really understand how to use the methods DestroyStructure() and FreeCoTaskMem().
I had 3 different kind of C# classes:
<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]<br />
public class myClassA<br />
{<br />
public Int32 n_elem;<br />
<br />
public IntPtr temperature = IntPtr.Zero;<br />
<br />
public IntPtr length = IntPtr.Zero;<br />
}<br />
<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]<br />
public class myClassB<br />
{<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]<br />
public char[] identifier = new char[8];<br />
<br />
public Double weight = 0F;<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]<br />
public Double[] coeffs = new Double[3];<br />
}<br />
<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]<br />
public myClassC<br />
{<br />
public IntPtr ptrClassA;<br />
<br />
public IntPtr ptrClassB;<br />
}<br />
First of all I create an object of myClassA and one of myClassB; then I correctly fill each members with appropriate data, then using Marshal.StructureToPtr() let ptrClassA point the myClassA object just created and the same for ptrClassB.
The line before calling the C dll I let a new IntPtr to reference the myClassC object, and then call the library
<br />
myClassA classAObject = new myClassA();<br />
myClassB classBObject = new myClassB();<br />
myClassC classCObject = new myClassC();<br />
<br />
classAObject.n_elem = rowsCount;
Double[] temp = new Double[rowsCount];<br />
Double[] len = new Double[rowsCount];<br />
{...}<br />
<br />
classAObject.temperature = ConvertEx.ArrayToPtr(temp) ;<br />
classAObject.length = ConvertEx.ArrayToPtr(len); <br />
<br />
classCObject.ptrClassA = ConvertEx.StructToPtr(classAObject );<br />
classCObject.ptrClassB = ConvertEx.StructToPtr(classBObject );<br />
<br />
IntPtr ptrIn = ConvertEx.StructToPtr(classCObject);<br />
<br />
CLibrary(ptrIn);<br />
<br />
StructToPtr and ArrayToPtr are static methods of a class ConvertEx which boxes the basic step to allocate unmanaged memory
<br />
public static IntPtr StructToPtr(Object oInstance)<br />
{<br />
IntPtr ret = IntPtr.Zero;<br />
Int32 size = Marshal.SizeOf(oInstance.GetType());<br />
ret = Marshal.AllocCoTaskMem(size);<br />
Marshal.StructureToPtr(oInstance, ret, true);<br />
return ret;<br />
}<br />
<br />
public static IntPtr ArrayToPtr(Int32[] oInstance)<br />
{<br />
Int32 elems = oInstance.GetLength(0);<br />
IntPtr ret = IntPtr.Zero;<br />
Int32 size = Marshal.SizeOf(oInstance[0].GetType())*elems;<br />
ret = Marshal.AllocCoTaskMem(size);<br />
Marshal.Copy(oInstance, 0, ret, elems);<br />
return ret;<br />
}<br />
<br />
Then i just call FreeCoTaskMem() for each IntPtr variable, but in fact memory is not correctly released, I think but i cannot find the right way i had to use DestroyStructure() and FreeCoTaskMem() .
Can anyone explain me the difference between DestroyStructure and FreeCoTaskMem or how to use in my application because in some MSDN examples it uses both methods: first DesroyStructure is called and then FreeCoTaskMem.
thanks in advance
cicciollo
|
|
|
|
|
how to access remote information but they dontknow. who accessing our information
plz send me the code in c# using windows application
|
|
|
|
|
1. You have been already told to read the forum guidelines. Let me refresh your memory.
2. Give the title of your message some meaning.
3. We don't just hand over code to people here. You need to at least try on your own.
4. What you are asking for sounds malicious and no one will help you do that.
|
|
|
|
|
That's called cracking, don't do it, its naughty
"You're very clever, young man, very clever," said the old lady. "But it's turtles all the way down!"
|
|
|
|
|
Even I make better posts than this. Shame, oh shame...
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
MasterSharp - we've never had you posting hacking questions. Marvelous.
|
|
|
|
|
Exactly.
- "Achieving all knowledge does not mean achieving all wisdom." some wise dude
- I love D-flat!
|
|
|
|
|
plz send me code in c#.net using windows application
|
|
|
|
|
sivaramireddy p wrote: plz send me code in c#.net using windows application
This was the best I could come up with given the vagueness of your request.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
Upcoming FREE developer events:
* Developer! Developer! Developer! 6
* Developer Day Scotland
My website
|
|
|
|
|
Sorry Colin thats doesn't compile in visual studio 2003 can you provide something even more vague.
|
|
|
|
|
Frank Kerrigan wrote: Sorry Colin thats doesn't compile in visual studio 2003
Sorry, I didn't realise you wanted something a bit more retro. Try this:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication3
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
Upcoming FREE developer events:
* Developer! Developer! Developer! 6
* Developer Day Scotland
My website
|
|
|
|