TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
bruno.marovelli
NA
1
0
Ok,no sound in this example: why?
Jun 24 2004 3:35 PM
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.InteropServices; namespace FreddyKrugherHomage { ///
/// Descrizione di riepilogo per Form1. ///
public class Freddy : System.Windows.Forms.Form { private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.Label lblDataOra; private System.ComponentModel.IContainer components; private System.Windows.Forms.Panel pnlEMI; private System.Windows.Forms.Timer timer2; public static int count = 1; static int dx = 4; static int dy = 4; static Size dimensione; const string FILE_NAME = "\\img\\Profondo rosso.wav"; public Freddy() { // // Necessario per il supporto di Progettazione Windows Form // InitializeComponent(); // // TODO: aggiungere il codice del costruttore dopo la chiamata a InitializeComponent // } ///
/// Pulire le risorse in uso. ///
protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Codice generato da Progettazione Windows Form ///
/// Metodo necessario per il supporto della finestra di progettazione. Non modificare /// il contenuto del metodo con l'editor di codice. ///
private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Freddy)); this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.lblDataOra = new System.Windows.Forms.Label(); this.pnlEMI = new System.Windows.Forms.Panel(); this.timer2 = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // // pictureBox1 // this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(752, 360); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); this.pictureBox1.DoubleClick += new System.EventHandler(this.pictureBox1_DoubleClick); // // timer1 // this.timer1.Enabled = true; this.timer1.Interval = 250; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // lblDataOra // this.lblDataOra.BackColor = System.Drawing.Color.Transparent; this.lblDataOra.Font = new System.Drawing.Font("Tahoma", 10.2F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.lblDataOra.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(0))); this.lblDataOra.Location = new System.Drawing.Point(560, 16); this.lblDataOra.Name = "lblDataOra"; this.lblDataOra.Size = new System.Drawing.Size(128, 40); this.lblDataOra.TabIndex = 1; this.lblDataOra.Text = "label1"; this.lblDataOra.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // pnlEMI // this.pnlEMI.BackColor = System.Drawing.Color.Transparent; this.pnlEMI.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pnlEMI.BackgroundImage"))); this.pnlEMI.Location = new System.Drawing.Point(280, 72); this.pnlEMI.Name = "pnlEMI"; this.pnlEMI.Size = new System.Drawing.Size(320, 136); this.pnlEMI.TabIndex = 2; this.pnlEMI.Visible = false; // // timer2 // this.timer2.Tick += new System.EventHandler(this.timer2_Tick); // // Freddy // this.AutoScaleBaseSize = new System.Drawing.Size(6, 15); this.BackColor = System.Drawing.SystemColors.WindowFrame; this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage"))); this.ClientSize = new System.Drawing.Size(696, 336); this.Controls.Add(this.pnlEMI); this.Controls.Add(this.lblDataOra); this.Controls.Add(this.pictureBox1); this.Cursor = System.Windows.Forms.Cursors.Hand; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Freddy"; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Form1"; this.Load += new System.EventHandler(this.Freddy_Load); this.ResumeLayout(false); } #endregion ///
/// Il punto di ingresso principale dell'applicazione. ///
[STAThread] static void Main() { Application.Run(new Freddy()); } private void Freddy_Load(object sender, System.EventArgs e) { dimensione = this.Size; if(!Sound.Play(FILE_NAME)) Application.Exit(); } private void pictureBox1_Click(object sender, System.EventArgs e) { timer2.Enabled = !timer2.Enabled ; pnlEMI.Visible = !pnlEMI.Visible; } private void pictureBox1_DoubleClick(object sender, System.EventArgs e) { Application.Exit(); } private void timer1_Tick(object sender, System.EventArgs e) { string oraEcc; System.DateTime oggiEora = DateTime.Today; oraEcc = oggiEora.Date.ToString(); oraEcc += oggiEora.Hour.ToString(); //n?? non va lblDataOra.Text = oraEcc; string img; img = "img\\" + Freddy.count.ToString() +".jpg"; this.pictureBox1.Image = Image.FromFile(img); Freddy.count++; if(Freddy.count == 36) Freddy.count = 1; //max immagini 36 img = ""; } private void timer2_Tick(object sender, System.EventArgs e) { pnlEMI.Left +=Freddy.dx; pnlEMI.Top +=Freddy.dy; if(pnlEMI.Location.X + pnlEMI.Size.Width> Freddy.dimensione.Width || pnlEMI.Location.X < 0 ) Freddy.dx = -Freddy.dx; if(pnlEMI.Location.Y + pnlEMI.Size.Height > Freddy.dimensione.Height || pnlEMI.Location.Y < 0 ) Freddy.dy = -Freddy.dy; } } internal class Helpers { [Flags] public enum PlaySoundFlags : int { SND_SYNC = 0x0000, /* play synchronously (default) */ SND_ASYNC = 0x0001, /* play asynchronously */ SND_NODEFAULT = 0x0002, /* silence (!default) if sound not found */ SND_MEMORY = 0x0004, /* pszSound points to a memory file */ SND_LOOP = 0x0008, /* loop the sound until next sndPlaySound */ SND_NOSTOP = 0x0010, /* don't stop any currently playing sound */ SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */ SND_ALIAS = 0x00010000, /* name is a registry alias */ SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */ SND_FILENAME = 0x00020000, /* name is file name */ SND_RESOURCE = 0x00040004 /* name is resource name or atom */ } [DllImport("winmm")] public static extern bool PlaySound( string szSound, IntPtr hMod, PlaySoundFlags flags ); } public class Sound { public static bool Play( string strFileName ) //+vedi che รจ statica... { return Helpers.PlaySound( strFileName, IntPtr.Zero, Helpers.PlaySoundFlags.SND_FILENAME | Helpers.PlaySoundFlags.SND_LOOP | Helpers.PlaySoundFlags.SND_ASYNC ); } } }
Reply
Answers (
0
)
Object reference not set to an instance of an object.
Find data in dataset and assign cell value to a variable