|
1 - if form1 holds the instance of form2, it can call a method on the form. Either way, a delegate is the nicest way to do this
2 - There's no control apart from the textbox
3 - The best way is to store user roles in a database. The issue is, if it's a windows app, people can just decompile your code and remove your authentication checks.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
1. What if i want to do the reverse, form2 calls a method in form1 when form1 holds the instance.
|
|
|
|
|
Hello,
Like Christian said before, a delegate would be the nicest way.
But you could also pass the instance from form1 to form2 (for example over the constructor).
All the best,
Martin
|
|
|
|
|
Ok thanks, never thought of that.
|
|
|
|
|
|
i don't know what to do really i've seen the code 100 times and it seem right
so if anyone can help....this's the code
public void ajout_dossier_image(string dossier,string matr)
{
if (Directory.Exists(dossier))
{ try
{
scanDirectory(dossier, "*.jpg", System.IO.SearchOption.TopDirectoryOnly);
String selectedImage = selectedImg;
if (imgList == null)
return;
foreach (String img in imgList) {ajout_image_seul(img, matr);}
}
catch (Exception exe) { MessageBox.Show("erreur du dossier de l'image");}
}
}
public void ajout_image_seul(string nom_img,string matr)
{
try
{
string date = "01/01/2005";//Convert.ToString(DateTime.Now)
string conStr = @"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=DermatoSoft_DB.mdb";
dataGridView1.DataSource = null;
ds = new DataSet();
conn = new OleDbConnection(conStr);
command = conn.CreateCommand();
conn.Open();
command.CommandText = "INSERT INTO Image (Numero_Patients,Nom_Image,Date_Image,"
+"Commentaire_Image) VALUES (" + matr + ",'" + nom_img + "','" + date + "','exemple commentaire')";
adapter = new OleDbDataAdapter(command);
adapter.Fill(ds);
conn.Close();
}
catch (Exception exe)
{
MessageBox.Show("erreur dans l'ajout de l'image");
}
}
thanks
|
|
|
|
|
What's happening when you run it?
If your getting an error what is it?
I think part of the problem is using the adapter.Fill method - I'm pretty sure that you need to use the Update method and also I'm not sure yoy sepcify a command text for the dataset - I thought you used an InsertCommand and calling update called the appropriate Commands with the change rows in the Dataset, and likewise the appropriate Update and Delete commands - been a while though so I could be wrong there - I'll look it up and let you know.....
|
|
|
|
|
my problem is that i used this command in other part and i'm sure that the command run
the error is that he cant make the instruction insert into
that there's an error in type
|
|
|
|
|
Well I was right in the first instance - if you look at the constructor for the OleDbDataAdapter - the command query which you pass in is for the SELECT command ONLY - so it's not going to take care of what you are trying to achieve here - you need to create an InsertCommand and then call update - that should fix it (maybe!)
|
|
|
|
|
i know the problem is that he don't wanna connect to the table image that i added but for the first table patient he can can connect this thing gonna make me crazy
so please can you tell me why csharp can access to an access table and not another and the two are in the same file
so please help
|
|
|
|
|
Thats's not the problem as far as I can see - sorry I'm struggling a bit with your english to understand what you are saying, but I think your issue is that the connection is fine - it's what you are trying to do with it is wrong. You can't use an INSERT (SQL) statement as a SelectCommand on the adapter and you can't use the Fill method on the adapter to call the InsertCommand - you have to use the Update method instead.
Perhaps you can put up the error and maybe that might cast some more light - but it looks as though it's just an issue with using the adapter incorrectly...
|
|
|
|
|
i tryed "select * from image" and they don't work
and i tryed "select * from patients" and they work
and the two table are in the same file named data_base.mdb
thanks anyway
|
|
|
|
|
Hmmm ok that is strange,
One thing that can occue on a SQL database is that case sensitivity can be on which means that a table called Image will not be found if you look for a table called image - no idea if that applies to an access database - but I guess it's worth a try?
|
|
|
|
|
Hi everyone,
I'm running into a problem while trying to format strings for printing. I'm working heavily with finance and I need the values to be flushed right and formatted as cash. Unfortunately none of the values are being formatted correctly. I assumed that if the String.Format() function was used correctly that the string would be returned with all the information needed to line it up correctly. I ran into a similar problem when trying to line up information in combo boxes. What I think is going on is that the width of a space is much smaller then the width of the characters in a font. Does anyone know of a workaround for this? Thanks. - Will
|
|
|
|
|
Sure, the easy way out is to display/print (parts of) the text using a so called
"non-proportional" font; such font has all characters (including the space char)
with the same width. An example is "Courier New".
|
|
|
|
|
Thanks Luc, That did the trick. I was trying to use system before because I thought it was lined up, but courier worked beautifully.
|
|
|
|
|
I made a C# application and i want the Textbox control to just take numbers and no characters. In VC++ this can be easily done by setting a property.
Any idea how to do this in C#?
Thanks
|
|
|
|
|
Handle the keypress event and check input
|
|
|
|
|
this is easy thing.
you can set as
:
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if ( !( char.IsDigit( e.KeyChar ) ) )
{
e.Handled = true;
}
}
roger wong
msn:wenmianbj@hotmail.com
|
|
|
|
|
The method you suggested works. Thanks.
One problem now is that the "Backspace" button no more works inside the text box.
Any idea why thats happening?
"Delete" button works.
|
|
|
|
|
U can use Regular Expression Validation control.
Validation Control will not allow other characters except numbers by setting the expression as ^[0-9]+$ in validation control
|
|
|
|
|
I was thinking about instead of having a normal boring form I wanted to make a custom UI but I am blanking on how to get a UI to work. I want to make it that there are tabs, or what not and if they click on it then it will animate it as it opens.
http://www.marcmercuri.com/content/binary/InfoCenter_Old.JPG
That is just an example...
I have done alot of this in Flash but in C# I have no idea where to start. Would I have to make the tab that I want to open a sprite? An animated GIF? I searched for quite a while and found tutorials using GDI+ and graphics but almost all describe making a small animated guy move across the screen. What I want to do is have the tab that is clicked to grow across the screen and then it will show more options. If it is clicked again it shrinks back into the tab on the side.
Any ideas or links to where I might look to find something like this would be great.
Thank you,
Rob
|
|
|
|
|
Ok, I got this working. I just used a sliding graphic and it works quite well. I just made the graphic slide in when clicked then auto go back. Making it stop and go back when clicked again is easy enough to add in. I am not sure how this will behave when I stick more then one slider on top of each other but it should be fine.
This is the bar graphic I am using.. http://themcclellanfamily.com/Bar.bmp (put this in your debug folder for the project)
This is the code I am using in case anyone wants to see or tweak it. It is nothing special, it is just a scrolling graphic but my plan is to make the tabs huge, someone clicks on it, it opens, loads in the controls, buttons, etc for that topic for that tab. They click on the open tab and it will remove the controls then close itself. Adding the controls dynamically is easy, this is what was giving me issues. Anywho...here is the code
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace sliding
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Timer t;
private System.Drawing.Size playerSize;
private System.Drawing.Point playerPosition;
bool back = false;
bool goFull = false;
bool stopMove = true;
int mouseX=0;
Image pic;
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
pic = Image.FromFile("Bar.bmp");
t = new Timer();
t.Interval = 40;
t.Tick += new System.EventHandler(TimerOnTick);
t.Enabled = true;
playerSize = new Size(540, 20);
playerPosition = new Point(-300, 20);
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Form1MouseClick);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(640, 480);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.Name = "Form1";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "Form1";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1MouseClick);
this.ResumeLayout(false);
}
private void TimerOnTick(object sender, System.EventArgs e)
{
if (this.PlayerPosition.X >-20)
{back = true;
goFull= false;
}
if (this.PlayerPosition.X < -300 && back==true)
{
goFull = false;
back = false;
stopMove= true;
}
if (!stopMove && back==false)
{this.PlayerPosition = new Point(this.PlayerPosition.X
+ 15,
this.PlayerPosition.Y);
goFull = true;
}
else if (!stopMove && back==true)
{this.PlayerPosition = new Point(this.PlayerPosition.X
- 15,
this.PlayerPosition.Y);
goFull = true;
}
this.Refresh();
this.Text = " " + this.PlayerPosition.ToString() + " "+mouseX+" "+stopMove;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
Graphics dc = e.Graphics;
dc.DrawImageUnscaled(pic, this.PlayerPosition);
base.OnPaint(e);
}
private Point PlayerPosition
{
get
{
return this.playerPosition;
}
set
{
this.playerPosition.X = value.X;
this.playerPosition.Y = value.Y;
}
}
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
void Form1MouseClick(object sender, MouseEventArgs e)
{
mouseX = e.X;
this.Text = Convert.ToString(e.X);
if (e.X < playerPosition.X + playerSize.Width && e.X > playerPosition.X && !stopMove &&goFull==false )
{
stopMove = true;
goFull = true;
}
else if (e.X < playerPosition.X + playerSize.Width && e.X > playerPosition.X && stopMove &&goFull==false)
{
goFull = true;
stopMove = false;
}
}
}
}
|
|
|
|
|
I am working on a project that needs to incorporate a C DLL. It is more like a wrapper to the DLL for C# developers. I have done some reading about unmanaged code in C#, importing a DLL and functions with the dllimport attribute. However I have not seen anything that is related to my situation.
The DLL has its own types, lets assume a connection (cxn) and a file (fh). Now I need to be able to use instances of those in C#. For example:
In C/C++ id just declare a new object
<br />
Cxn my_cxn; <br />
....<br />
Then I could go on and use that as a parameter to other functions.
How do I do this in C#?
Also, I think I am on track for strings. All of the functions in the DLL use LPCWSTR strings. So I am using the MarshalAS attribute to specify this. Example:
<br />
[DllImport("mylib.dll", CharSet=CharSet.Unicode)]<br />
static extern int CxnOpen([MarshalAs(UnmanagedType.LPWStr)] string smtp,<br />
[MarshalAs(UnmanagedType.LPWStr)] string http,<br />
[MarshalAs(UnmanagedType.LPWStr)] string dom,<br />
[MarshalAs(UnmanagedType.LPWStr)] string rep,<br />
IntPtr temp);<br />
|
|
|
|
|
Newbie quests...
How do you compile with the /unsafe option from VS2005? Also, GetHashCode returns a generated HashCode for a variable. Conversely, how do you return the original value from the code created?
Jon
|
|
|
|