|
Well, in my program, the user type the path of the image.
string with the path is: imagepath
I tryed:
Image img = Image.FromFile( imagepath );
but this ONLY WORKS if the IMAGEPATH ( users type ) is the SAME of the PROGRAM PATH.
If the program path is different, this doesnt work...
So i tryed a FileStream and Image.FromStream, same problem, only works if the program path = IMAGEPATH
What can i do?
Thanks.
|
|
|
|
|
Hi Moon B,
Image img = Image.FromFile( imagepath );
In place of "imagepath" you can enter
1. image file name with extension like "mypic.bmp", "mypic1.ico" etc or.
2. You can enter the image full path like
Image.FromFile(@"C:\Jay Code\mypic.bmp")
In Case 1 mypic should be in Application's Main/Bin/Debug folder where exe is being stored.
In case 2 it takes absolute bath that is why application directory does not matter.
Try the code mentioned in 2, if it does not work revert back..
Jay
|
|
|
|
|
Hi Guys,
I've created a program in c# that reads data from different port at the same time - so far it was ok connection to 5 ports at the same time using sockets. My concern now is if the administrator from one of the ports "KILL" or "TERMINATE" that particular port my program doesn't catch it. I'm using socketexcetopn as my CATCH and at the same time ObjectDisposedException still no luck. If you run NETSTAT from "cmd" you can see that the connection is "CLOSE_WAIT". What happen is that the connection will always be there. My program is running on 24hrs everyday.
I need to monitor that becuase if it's disconnected I need to reconnect it again.
CODE:
socketList[arrcnt] = new Socket(AddressFamily.InterNetwork,SocketType.Stream ,ProtocolType.Tcp );
IPAddress ip = IPAddress.Parse (stripd);
Int32 iPortNo = System.Convert.ToInt32 ( strport);
IPEndPoint ipEnd = new IPEndPoint(ip.Address, iPortNo);
socketList[arrcnt].Connect (ipEnd);
WaitForData(socketList[arrcnt]);
CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState ;
try
{
//end receive...
int iRx = 0 ;
iRx = theSockId.thisSocket.EndReceive (asyn);
if (theSockId.dataBuffer == null)
{
int sam = System.Environment.TickCount;
}
char[] chars = new char[iRx]; // + 1];
System.Text.Decoder d = System.Text.Encoding.ASCII.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
StringBuilder szData = new StringBuilder();
szData.Append(chars);
WaitForData(theSockId.thisSocket);
}
catch (ObjectDisposedException)
{}
catch(SocketException se)
{System.Diagnostics.EventLog.WriteEntry("ossrop on datareceived",theSockId.thisSocket.RemoteEndPoint.ToString() + " " + se.Message);
}
Any help or explanation will do. Thanks in advance.
/dabuskol
|
|
|
|
|
Hi,
I'm writting a program for pocketpc using c#. I need to call and execute another program. It looks like the compact framework doesn't have the class "process", so I can't use the System.Diagnostics.Process.Start(...)
Does anyone have a solution to this? Great thank for any suggestion.
|
|
|
|
|
The simplest thing to do is to grab the OpenNETCF class libraries, which contain a class OpenNETCF.Diagnostics.Process which almost exactly replaces the missing class. See OpenNETCF Smart Device Framework[^].
If you don't want to be dependent on third-party components, use P/Invoke to call the CreateProcess or ShellExecute APIs.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
|
Have an Access DB A table called Zips and Field called zipcodes. I can get the data at the console.writeline but the combobox shows nothing. Any ideas.
private void property_Load(object sender, System.EventArgs e)
{
string strDSN="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\ARM1\\database\\utility.MDB;Jet OLEDB:Database Password=rival";
string strSQL="Select * FROM zips";
//Connection Object
OleDbConnection connection = new OleDbConnection(strDSN);
OleDbCommand MyCmd=new OleDbCommand(strSQL,connection);
connection.Open();
OleDbDataReader rsZips=MyCmd.ExecuteReader();
ArrayList load = new ArrayList();
while(rsZips.Read())
{
load.Add(rsZips["zipcodes"].ToString());
}
this.comboBox1.DataSource=load;
comboBox1.DisplayMember="zipcodes";
for (int cnt = 0; cnt < load.Count; cnt++)
{
string anItem = load[cnt].ToString();
comboBox1.Items.Add(anItem);
Console.WriteLine(anItem);
}
connection.Close();
}
TIA Jim
|
|
|
|
|
Hi Jimbo,
If you getting the data at the console, The combo box should also get populated.
I suppose u do not require the code line
this.comboBox1.DataSource=load;
since u are traversing the data using for loop.
comment the line of code(this.comboBox1.DataSource=load;
)
U will get the result.
Do revert back if u are still unable to solve.
Jay.
|
|
|
|
|
This didn't work. The combobox seems to be populated but nothing appears.
Here is the code for the whole form. Maybe this can shed some light. Jim
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace mdisample
{
///
/// Summary description for property.
///
public class property : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public property()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.label2 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.AutoScroll = true;
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.comboBox1);
this.panel1.Controls.Add(this.label1);
this.panel1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.panel1.Location = new System.Drawing.Point(8, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(600, 300);
this.panel1.TabIndex = 0;
//
// label2
//
this.label2.Location = new System.Drawing.Point(144, 56);
this.label2.Name = "label2";
this.label2.TabIndex = 2;
//
// comboBox1
//
this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Location = new System.Drawing.Point(288, 56);
this.comboBox1.MaxDropDownItems = 20;
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(216, 21);
this.comboBox1.Sorted = true;
this.comboBox1.TabIndex = 1;
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(248, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(304, 16);
this.label1.TabIndex = 0;
this.label1.Text = "Please select the Zipcode you are looking for.";
//
// property
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(680, 273);
this.Controls.Add(this.panel1);
this.Name = "property";
this.Text = "Property";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.property_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/*================================================
* Directory scanner Not used because we bind to the DB
* ===============================================*/
void DirToLbox(string targetPath, ListBox myListBox)
{
// create an array to hold the subdirectories
ArrayList sArray=new ArrayList();
// create an array to hold the list of files
ArrayList fArray=new ArrayList();
// get information about our initial directory
DirectoryInfo dirInfo=new DirectoryInfo(targetPath);
// retrieve array of files & subdirectories
FileSystemInfo[] myDir=dirInfo.GetFileSystemInfos();
for (int i=0; i<mydir.length; i++)=""
="" {
="" check="" the="" file="" attributes
="" if="" a="" subdirectory,="" add="" it="" to="" sarray="" otherwise,="" farray
="" (((convert.tobyte(mydir[i].attributes)="" &="" convert.tobyte(fileattributes.directory)="" )=""> 0 ))
sArray.Add(Path.GetFileName(myDir[i].FullName)
+ "\\");
else
fArray.Add(Path.GetFileName(myDir[i].FullName));
}
// sort the subdirectories alphabetically
sArray.Sort(0,sArray.Count,null);
// sort the files alphabetically
fArray.Sort(0,fArray.Count,null);
// ensure that the listbox has no items beforehand
myListBox.Items.Clear();
// insert the sorted subdirectories into the listbox
for (int i=0; i
|
|
|
|
|
Hi Jimbo,
Comment the following line
<br />
this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;<br />
<br />
this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.Normal;
the code will work.
In case if you are unable to get the result. Do revert back.
Regards,
Jay
|
|
|
|
|
I am making a screensaver of sorts and I am trying to detect when p,P, or escape key is pressed. When i would hit p the screensaver would stop but upon hitting p again it should have started up again but had no response so i changed it to this.
construct...
this.KeyUp += new KeyEventHandler(OnKeyPress); ...
public void OnKeyPress(object o, KeyEventArgs e) {
switch(e.KeyCode) {
case Keys.Escape:
Application.Exit();
break;
default:
break;
}
}
all the examples i was able to locate show using a frikin textbox... i just want the form to check and handle necessary actions required.
codemonkey
aspiring programmer
|
|
|
|
|
Hi
I do not know if I'm get it right but from what you say :
there is property of the form which when you set it to true also the form keypressed and key up key down raises .
frmMain.KeyPreview = true ;
then you can use form 's event to handle what you want.
|
|
|
|
|
Hi, im trying to get a image from a path.
foto is a string path espec. by the user.
FileStream f = new FileStream( foto, FileMode.Open ); <br />
Image img = Image.FromStream( f );
This doesnt working, its only works if the image is in the same folder of the program =/
Thanks.
|
|
|
|
|
Hi, im trying to get a image from a path.
foto is a string path espec. by the user.
FileStream f = new FileStream( foto, FileMode.Open ); <br />
Image img = Image.FromStream( f );
This doesnt working, its only works if the image is in the same folder of the program =/
Thanks.
|
|
|
|
|
MoOnBoY wrote:
Image.FromStream( f );
I think there is a better way!
Just use:
Image img = Image.FromFile("C:\\...");
Oh, and a little correction:
This doesnt working, its only works if the image is in the same folder of the program.
This doesn't work. Its only working if the image is in the same folder as the program.
;);) Just kidding ;););)
Good luck!
|
|
|
|
|
The path is specificated by the USER...
foto is the path, if I use: Image img = Image.FromFile( foto ); Only works if the path is the same of program folder....
|
|
|
|
|
Let's say we have a textBox called textBox1 .
And let's say we hava a picture box called pictureBox1 .
We use pictureBox1 to view the image.
The user types in the CORRECT path.
The user clicks on a button.
And now the button's OnClick event:
Image img = Image.FromFile (<font color=#0000ff>this</font>.textBox1.Text);<br />
<font color=#0000ff>this</font>.pictureBox1.Image = img;
Then add an error handling with TRY and CATCH.
I've already tested this code.
It MUST work.
|
|
|
|
|
If the path is specified by the user then use
Image img = Image.FromFile ( @foto );
|
|
|
|
|
as i understood that u ve image and u want to open it from stream file...
1-u cant use Image class as it is abstract one, so u cant define object from it
2-u use Bitmap class to open ur image
//example: dont forget to use (Using System.Drawing)
Bitmap myimage=new Bitmap(filestream,true);
//constructor use true to make error correction..hope it works
|
|
|
|
|
Hello,
I'm developing some windows based application. I have made a setup to deploy the application to some other computer. I want to deploy an application for only 15 days. Or you can say that i want to deploy an application as trail version of 15 days for testing purpose. After 15 days, application should be stoped working automatically. Hopefully, someone will understand my question and will reply me as soon as possible.
Thanks.
|
|
|
|
|
IF your are asking a question like this, i doubt anyone would buy the app. :\
|
|
|
|
|
Infact, i have to deploy the application for testing purpose to the company before the final deployment. So instead of giving me this answer, reply me the solution.
Thanks.
|
|
|
|
|
There are multiple ways and there are also a multitude of companies that make a living off of providing this type of solution. I don't think there is an easy solution that can be posted to the forum.
The easiest way would probably be using a registry key added upon instalation and some code in the app that checks the key and compares a date against a certain period of time.
Here are some long list of companies providing ready made components. I only see one open source one but there may be more.
http://dmoz.org/Computers/Software/Licensing/License_Management/
http://dmoz.org/Computers/Security/Products_and_Tools/Software_Protection_and_License_Control/
--------------------
It is what is is!
|
|
|
|
|
there are C++ examples, such as Nish's one[^] that do what you are asking, maybe you can port those over to C#.
To those who didn't make it, we will remember you. To those who did is back. - Megan Forbes in Black FridayAnother Post by NnamdiOnyeyiri
|
|
|
|
|
Hi
Is there any method by which I can make an app transparent...like even if it appears(not completely transparent), it should not respond to mouse clicks (say if the ctrl key wasnt pressed along with a mouse click) and should transfer the ctrl to the app behind it...
Example:
Letz a scoreboard display and behind it IE...u dont need any user triggered event for it...so even if i click in the display, IE should respond and not the display..
Is there any method in C#?
Thanks
|
|
|
|