penchu
Messages postés
167
Date d'inscription
mercredi 11 février 2004
Statut
Membre
Dernière intervention
5 janvier 2006
24 févr. 2005 à 15:02
voici tout mon code complet : en fait c'est le netsender que j'ai posté il y a peu.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.IO;
namespace NetSender_1._0
{
/// <summary>
/// Description résumée de Form1.
/// </summary>
public
class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private NETXP.Components.NotifyIconEx notifyIconEx1;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox2;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Requis pour la prise en charge du Concepteur Windows Forms
//
InitializeComponent();
this.comboBox1.Items.Add("Contremaitres");
this.comboBox1.Items.Add("Jeremy");
this.comboBox1.Items.Add("Jlf");
this.comboBox1.Items.Add("Jose-xp");
this.comboBox1.Items.Add("Pc-damien");
this.comboBox1.Items.Add("Pc-encres");
this.comboBox1.Items.Add("Pc-koen");
this.comboBox1.Items.Add("Pc-magasin");
this.comboBox1.Items.Add("Pc-table");
this.comboBox1.Items.Add("Secretariat");
this.comboBox1.Items.Add("Thierry-penta");
//
// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
//
}
/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected
override
void Dispose(
bool disposing )
{
if( disposing )
{
if (components !=
null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Code généré par le Concepteur Windows Form
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private
void InitializeComponent()
{
this.components =
new System.ComponentModel.Container();
System.Resources.ResourceManager resources =
new System.Resources.ResourceManager(
typeof(Form1));
this.button1 =
new System.Windows.Forms.Button();
this.label1 =
new System.Windows.Forms.Label();
this.label2 =
new System.Windows.Forms.Label();
this.textBox1 =
new System.Windows.Forms.TextBox();
this.button2 =
new System.Windows.Forms.Button();
this.button3 =
new System.Windows.Forms.Button();
this.notifyIconEx1 =
new NETXP.Components.NotifyIconEx();
this.toolTip1 =
new System.Windows.Forms.ToolTip(
this.components);
this.comboBox1 =
new System.Windows.Forms.ComboBox();
this.textBox2 =
new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.BackColor = System.Drawing.Color.WhiteSmoke;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location =
new System.Drawing.Point(88, 152);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "&Envoyer";
this.toolTip1.SetToolTip(
this.button1, "Cliquez ici pour envoyer votre message");
this.button1.Click +=
new System.EventHandler(
this.button1_Click);
//
// label1
//
this.label1.Font =
new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.ForeColor = System.Drawing.Color.WhiteSmoke;
this.label1.Location =
new System.Drawing.Point(16, 24);
this.label1.Name = "label1";
this.label1.Size =
new System.Drawing.Size(64, 23);
this.label1.TabIndex = 1;
this.label1.Text = "Nom";
//
// label2
//
this.label2.Font =
new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.ForeColor = System.Drawing.Color.WhiteSmoke;
this.label2.Location =
new System.Drawing.Point(16, 56);
this.label2.Name = "label2";
this.label2.Size =
new System.Drawing.Size(64, 23);
this.label2.TabIndex = 2;
this.label2.Text = "Message";
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
this.textBox1.Font =
new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.textBox1.ForeColor = System.Drawing.Color.Maroon;
this.textBox1.Location =
new System.Drawing.Point(88, 24);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button2
//
this.button2.BackColor = System.Drawing.Color.WhiteSmoke;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button2.Location =
new System.Drawing.Point(248, 152);
this.button2.Name = "button2";
this.button2.Size =
new System.Drawing.Size(32, 23);
this.button2.TabIndex = 3;
this.button2.Text = "&?";
this.toolTip1.SetToolTip(
this.button2, "Afficher l\'aide");
this.button2.Click +=
new System.EventHandler(
this.button2_Click);
//
// button3
//
this.button3.BackColor = System.Drawing.Color.WhiteSmoke;
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button3.Location =
new System.Drawing.Point(288, 152);
this.button3.Name = "button3";
this.button3.TabIndex = 4;
this.button3.Text = "&Quitter";
this.toolTip1.SetToolTip(
this.button3, "Quitter Net Sender 1.1");
this.button3.Click +=
new System.EventHandler(
this.button3_Click);
//
// notifyIconEx1
//
this.notifyIconEx1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIconEx1.Icon")));
this.notifyIconEx1.Text = "Net Sender 1.1";
this.notifyIconEx1.Visible =
true;
this.notifyIconEx1.RightClick +=
new System.EventHandler(
this.notifyIconEx1_RightClick);
this.notifyIconEx1.Click +=
new System.EventHandler(
this.notifyIconEx1_Click);
this.notifyIconEx1.DoubleClick +=
new System.EventHandler(
this.notifyIconEx1_DoubleClick);
//
// comboBox1
//
this.comboBox1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
this.comboBox1.ForeColor = System.Drawing.Color.Maroon;
this.comboBox1.Location =
new System.Drawing.Point(248, 24);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size =
new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 5;
this.comboBox1.Text = "Nom";
this.toolTip1.SetToolTip(
this.comboBox1, "Liste des ordinateurs présents sur le réseau");
this.comboBox1.SelectedIndexChanged +=
new System.EventHandler(
this.comboBox1_SelectedIndexChanged);
//
// textBox2
//
this.textBox2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
this.textBox2.Font =
new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.textBox2.ForeColor = System.Drawing.Color.Maroon;
this.textBox2.Location =
new System.Drawing.Point(88, 56);
this.textBox2.Multiline =
true;
this.textBox2.Name = "textBox2";
this.textBox2.Size =
new System.Drawing.Size(280, 88);
this.textBox2.TabIndex = 6;
this.textBox2.Text = "";
//
// Form1
//
this.AutoScaleBaseSize =
new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.DarkBlue;
this.ClientSize =
new System.Drawing.Size(376, 182);
this.Controls.Add(
this.textBox2);
this.Controls.Add(
this.comboBox1);
this.Controls.Add(
this.button3);
this.Controls.Add(
this.button2);
this.Controls.Add(
this.textBox1);
this.Controls.Add(
this.label2);
this.Controls.Add(
this.label1);
this.Controls.Add(
this.button1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "NetSender 1.1";
this.Resize +=
new System.EventHandler(
this.Form1_Resize);
this.Load +=
new System.EventHandler(
this.Form1_Load);
this.ResumeLayout(
false);
}
#endregion
/// <summary>
/// Point d'entrée principal de l'application.
/// </summary>
[STAThread]
static
void Main()
{
Application.Run(
new Form1());
}
private
void button3_Click(
object sender, System.EventArgs e)
{
this.Close();
}
private
void button2_Click(
object sender, System.EventArgs e)
{
Form2 aide =
new Form2();
aide.Show();
}
private
void button1_Click(
object sender, System.EventArgs e)
{
if ((
this.textBox1.Text=="")&&(
this.textBox2.Text==""))
{
MessageBox.Show("Vous devez remplir les champs Nom d'hôte et Message pour pouvoir envoyer.","Champs vides");
}
//j'ai rajouté ce code (msdn power) qui permet de ne pas lancer de fenêtre DOS lors de l'envoi du message
Process send =
new Process();
ProcessStartInfo startInfo =
new ProcessStartInfo("net.exe");
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(startInfo);
startInfo.Arguments = " send "+
this.textBox1.Text+" "+
this.textBox2.Text;
Process.Start(startInfo);
//this.textBox1.Text="";
this.textBox2.Text="";
this.textBox2.Focus();
//pour l'enregistrement dans le fichier log
FileStream fs =
new FileStream(@"C:\Program Files\NetSender 1.1\fichier.log",FileMode.Append,FileAccess.Write);
StreamWriter sw =
new StreamWriter(fs);
StreamWriter sw2 =
new StreamWriter(fs);
sw.WriteLine(System.DateTime.Now.ToLongDateString() +" "+System.DateTime.Now.ToLongTimeString());
sw.WriteLine("----------------------------------");
sw.WriteLine("Envoyé à "+
this.textBox1.Text.ToUpper());
sw.WriteLine("Message : "+
this.textBox2.Text);
sw.WriteLine();
sw.WriteLine();
sw.Close();
fs.Close();
}
private
void Form1_Resize(
object sender, System.EventArgs e)
{
if (
this.WindowState == FormWindowState.Minimized)
{
this.Hide();
this.ShowInTaskbar =
false;
this.textBox1.Text="";
this.textBox2.Text="";
}
}
private
void RevoirForm ()
{
this.ShowInTaskbar =
true;
this.Show();
this.WindowState = FormWindowState.Normal;
}
private
void notifyIconEx1_Click(
object sender, System.EventArgs e)
{
RevoirForm();
}
private
void notifyIconEx1_DoubleClick(
object sender, System.EventArgs e)
{
RevoirForm();
}
private
void notifyIconEx1_RightClick(
object sender, System.EventArgs e)
{
RevoirForm();
}
private
void Form1_Load(
object sender, System.EventArgs e)
{
this.notifyIconEx1.ShowBalloon("Net Sender 1.1","Cliquez sur cette icône pour renvoyer un message.",NETXP.Components.NotifyInfoFlags.Info,3000);
}