public ScrollingText() { InitializeComponent(); this.DoubleBuffered = true; this.BackgroundColor = Color.Black; this.TextColor = Color.Red; this.Speed = DEFAULT_SPEED; this.HeightPercentage = DEFAULT_HEIGHT; this.BackColor = Color.Black; _speed = DEFAULT_SPEED; _timer = new Multimedia.Timer(); _timer.Period = _speed; _timer.Tick += TickHandler; _timer.Start(); _position = 0; //Set up the resize event to set the height of the control this.Resize += ResizeHandler; _tempHeight = this.Height; }
private void initTimer(int period) { timer.Period = Convert.ToInt32(1000 / Convert.ToDecimal(period)); timer.Resolution = 1; timer.Tick += new EventHandler(timer_GameTick_Tick); timer.Start(); }
public void SendCommand(Command command_out) { try { if (command_out != null) { if (udpClient.Available > 1) //вычитываем из порта все если там что-то есть { byte[] tmp = new byte[udpClient.Available]; udpClient.Receive(tmp); } int n = udpClient.SendTo(command_out.GetCommandByteBuf(), endPointTo); //command_in = command_out; command_in = new Command(1000); command_in.index = command_out.index; command_in.set_or_get = command_out.set_or_get; state_rx = STATE_RX.ADDR; time = (long)command_in.timeOut; com_timer.Start(); } } catch (Exception ex) { throw ex; } }
/* Handles the click on the continuous frame button. */ private void toolStripButtonContinuousShot_Click(object sender, EventArgs e) { /*ContinuousShot(); /* Start the grabbing of images until grabbing is stopped. */ my_trigger = new Multimedia.Timer(); my_trigger.Resolution = 0; my_trigger.Period = (int)trigger_period.Value; my_trigger.Tick += new EventHandler(get_single_frame); my_trigger.Start(); }
private void btnAnimStart_Click(object sender, EventArgs e) { btnAnimStop.Enabled = true; btnAnimStart.Enabled = false; btnAnimNext.Enabled = false; int index = cboEntry.SelectedIndex; ms = GfxBattleBg.Masters[index]; for (int i = 0; i < 2; i++) { try { bgAlphas[i] = int.Parse(txtAlpha[i].Text); } catch { txtAlpha[i].SelectAll(); return; } bgLayers[i] = cboLayer[i].SelectedIndex; srcBitmap[i] = GfxBattleBg.GetBg(index, i); if (changed) { srcPal[i] = (MPalette)GfxBattleBg.Bgs[bgLayers[i]].Palette.Clone(); } srcBd[i] = srcBitmap[i].LockBits(ImageLockMode.ReadWrite); bufBitmap[i] = new Bitmap(256, 256, PixelFormat.Format8bppIndexed); bufBd[i] = bufBitmap[i].LockBits(ImageLockMode.ReadWrite); buf[i] = (byte *)bufBd[i].Scan0; dstBitmap[i] = new Bitmap(256, 256, PixelFormat.Format8bppIndexed); // Apply the alphas alphaAttr[i] = new ImageAttributes(); float a = bgAlphas[i]; alphaMatrix[i] = new ColorMatrix(); alphaMatrix[i].Matrix33 = a / 16.0f; alphaAttr[i].SetColorMatrix(alphaMatrix[i], ColorMatrixFlag.Default, ColorAdjustType.Bitmap); } if (changed) { changed = false; t = 0; } pAnimation.Visible = true; tm.Start(); }
/// <summary> /// Starts the video capture /// </summary> /// <param name="FrameNumber">the frame number to start at. /// Set to 0 to let the control allocate the frame number</param> public void Start(ulong frameNumber) { try { // for safety, call stop, just in case we are already running this.Stop(); // setup a capture window m_captureHandlerWindow = WebCamAPI.capCreateCaptureWindowA("WebCap", 0, 0, 0, ImageWidth, ImageHeight, this.Handle.ToInt32(), 0); // connect to the capture device Application.DoEvents(); WebCamAPI.SendMessage(m_captureHandlerWindow, WebCamAPI.WM_CAP_CONNECT, 0, 0); WebCamAPI.SendMessage(m_captureHandlerWindow, WebCamAPI.WM_CAP_SET_PREVIEW, 0, 0); // set the capture video format (width and height) to the value of the params given at c'tor WebCamAPI.BitMapInfo bInfo = new WebCamAPI.BitMapInfo(); bInfo.bmiHeader = new WebCamAPI.BitMapInfoHeader(); bInfo.bmiHeader.biSize = (uint)Marshal.SizeOf(bInfo.bmiHeader); bInfo.bmiHeader.biWidth = ImageWidth; bInfo.bmiHeader.biHeight = ImageHeight; bInfo.bmiHeader.biPlanes = 1; bInfo.bmiHeader.biBitCount = 24; IntPtr buffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(bInfo)); Marshal.StructureToPtr(bInfo, (IntPtr)buffer, true); WebCamAPI.SendMessage(m_captureHandlerWindow, WebCamAPI.WM_CAP_SET_VIDEOFORMAT, Marshal.SizeOf(bInfo), (int)buffer); // set the frame number this.FrameNumber = frameNumber; // set the timer information //this.m_captureTimer.Interval = this.CaptureInterval; m_timer.Period = this.CaptureInterval; m_stopped = false; m_timer.Start(); //this.m_captureTimer.Start(); } catch (Exception excep) { string errorMsg = "An error ocurred while starting the video capture. Check that your webcamera is connected properly and turned on." + Environment.NewLine + "Error: " + excep.Message; MessageBox.Show(this, errorMsg, "Start Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Stop(); } }
//Подключение по COM private void BtnConnect_Click(object sender, RoutedEventArgs e) { if (_port == null || !_port.IsOpen) { _port = new SerialPort(); try { _port.PortName = Convert.ToString(CbPortName.SelectionBoxItem); _port.BaudRate = Convert.ToInt32(CbBaudRate.SelectionBoxItem); _port.StopBits = StopBits.One; _port.DataBits = 8; _port.StopBits = StopBits.One; _port.Parity = Parity.Even; _port.ReadTimeout = RecieveTimeOut; _port.Open(); _timer.Start(); BtnConnect.Content = "Отключить"; LbConnectionStatus.Content = "Статус: Подключено"; } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); return; } } else { // В отключения переподключения сбрасываем команду _command = 0x00; _timer.Stop(); _port.Close(); BtnConnect.Content = "Подключить"; LbConnectionStatus.Content = "Статус: Отключено"; } // Включаем кнопки управления foreach (var toggleButton in _tlgBtnList) { toggleButton.IsEnabled = !toggleButton.IsEnabled; toggleButton.IsChecked = false; } CbPortName.IsEnabled = !CbPortName.IsEnabled; CbBaudRate.IsEnabled = !CbBaudRate.IsEnabled; }
public bool ConnectCapture(int indexVideoDevice, int indexVideoInput, int indexSizeVideo) { try { videoDevice = new VideoCaptureDevice(videoDevices[indexVideoDevice].MonikerString); if (videoCapabilities != null) { if (indexVideoInput != -1) { videoDevice.CrossbarVideoInput = videoDevice.AvailableCrossbarVideoInputs[indexVideoInput]; } if (indexSizeVideo != -1) { videoDevice.VideoResolution = videoCapabilities[indexSizeVideo]; } } frmMain.videoSourcePlayer.VideoSource = videoDevice; //frmMain.videoSourcePlayer.Location = new System.Drawing.Point(0, 0); //frmMain.videoSourcePlayer.Size = new Size(videoDevice.VideoResolution.FrameSize.Width, videoDevice.VideoResolution.FrameSize.Height); frmMain.videoSourcePlayer.NewFrame += videoSourcePlayer_NewFrame; videoDevice.Start(); tmr.Start(); } catch { return(false); } return(true); }
private void Tick() { var deltaTime = ((double)deltaClock.ElapsedMilliseconds / 1000d); deltaClock.Restart(); tickClock.Restart(); for (var i = 0; i < registeredGameComponents.Count; i++) { registeredGameComponents[i].Tick(deltaTime); } var elapsedExecutionTime = (int)tickClock.ElapsedMilliseconds; var delayTime = tickDelay - elapsedExecutionTime; if (IsRunning) { if (delayTime <= Multimedia.Timer.Capabilities.periodMin) { Tick(); } else { mediaTimer = new Multimedia.Timer() { Period = tickDelay - elapsedExecutionTime, Mode = Multimedia.TimerMode.OneShot }; mediaTimer.Tick += (s, e) => Tick(); mediaTimer.Start(); } } else { this.CleanUp(); } }
private void CreateRandomObjects() { #if WINFORMS tmr.Stop(); #endif Thread.Sleep(15); // Give the SimLoop enough time to finish bodies.Clear(); forces.Clear(); switch (mode) { case Modes.Standard: Random rnd = new Random(); int n = rnd.Next(3, (int)Math.Sqrt(bounds.Width)); double mass; double x; double y; for (int i = 0; i < n; i++) { while (true) { bool isValid = true; mass = rnd.NextDouble() * 100 + 20; x = rnd.NextDouble() * bounds.Width - bounds.Width / 2; y = rnd.NextDouble() * bounds.Height - bounds.Height / 2; RectangleF r = new RectangleF((float)(x - mass / 2) - 5, (float)(y - mass / 2) - 5, (float)mass + 10, (float)mass + 10); if (x - mass / 2 < bounds.X || y - mass / 2 < bounds.Y || x + mass > bounds.Width / 2 || y + mass > bounds.Height) { isValid = false; } else { for (int j = 0; j < bodies.Count; j++) { double m = bodies[j].Mass; RectangleF rp = new RectangleF((float)(bodies[j].X1 - m / 2), (float)(bodies[j].Y1 - m / 2), (float)m, (float)m); rp.Inflate(5, 5); #if WINFORMS if (rp.IntersectsWith(r)) { #else if (rp.Intersects(r)) { #endif isValid = false; break; } } } if (isValid) { break; } } bodies.Add(new Body2D(mass, x, y) { Color = Color.FromArgb((int)(rnd.NextDouble() * 255), (int)(rnd.NextDouble() * 255), (int)(rnd.NextDouble() * 255)) }); } forces.Add(gravity); forces.Add(wind); break; case Modes.Planetarium: #if WINFORMS bodies.Add(new Body2D(200, 0, 0) { Color = Color.Yellow, Movable = false }); bodies.Add(new Body2D(30, 700, 0) { Color = Color.DeepSkyBlue, HistorySize = 1000 }); bodies[1].Velocity = new Vector(200, 90 * Constants.ToRad, bodies[1].Origin); bodies.Add(new Body2D(20, 0, -500) { Color = Color.OrangeRed, HistorySize = 1000 }); bodies[2].Velocity = new Vector(200, 0 * Constants.ToRad, bodies[2].Origin); bodies.Add(new Body2D(40, -500, 0) { Color = Color.YellowGreen, HistorySize = 1000 }); bodies[3].Velocity = new Vector(220, 290 * Constants.ToRad, bodies[3].Origin); #else bodies.Add(new Body2D(200, 0, 0) { Color = Colors.Yellow, Movable = false }); bodies.Add(new Body2D(30, 700, 0) { Color = Colors.DeepSkyBlue, HistorySize = 1000 }); bodies[1].Velocity = new Vector(200, 90 * Constants.ToRad, bodies[1].Origin); bodies.Add(new Body2D(20, 0, -500) { Color = Colors.OrangeRed, HistorySize = 1000 }); bodies[2].Velocity = new Vector(200, 0 * Constants.ToRad, bodies[2].Origin); bodies.Add(new Body2D(40, -500, 0) { Color = Colors.YellowGreen, HistorySize = 1000 }); bodies[3].Velocity = new Vector(220, 290 * Constants.ToRad, bodies[3].Origin); #endif break; } #if WINFORMS tmr.Start(); #endif }
public TriggerTask(Action callback, long delayMilliseconds) { _callback = callback; _delayMilliseconds = delayMilliseconds; _sw = new Stopwatch(); _scanTask = true; //_mmTimer = new MMTimer(); //_mmTimer.Timer += (senser, ea) => //{ // if (_scanTask) // { // if (this.IsRunning && _callback != null) // { // if (_sw.ElapsedMilliseconds > _delayMilliseconds) // { // _callback.Invoke(); // Stop(); // } // } // } //}; //_mmTimer.Start(1, true); mmTimer = new Multimedia.Timer(ModulesFactory.Components); mmTimer.Mode = Multimedia.TimerMode.Periodic; mmTimer.Period = 1; mmTimer.Resolution = 1; mmTimer.Tick += (senser, ea) => { if (_scanTask) { if (this.IsRunning && _callback != null) { if (_sw.ElapsedMilliseconds > _delayMilliseconds) { _callback.Invoke(); Stop(); } } } }; mmTimer.Start(); //_thread = new Thread(() => //{ // uint loops = 0; // while (_scanTask) // { // if (this.IsRunning && _callback != null) // { // if (_sw.ElapsedMilliseconds > _delayMilliseconds) // { // _callback.Invoke(); // Stop(); // } // } // loops = (loops + 1) % 100; // if (Environment.ProcessorCount == 1 || loops == 0) // { // Thread.Sleep(1); // } // else // { // //Thread.SpinWait(_iterations); // Wait(1); // } // } //}); //_thread.IsBackground = true; //_thread.Start(); }
private void FrameSender_Load(object sender, EventArgs e) { fastTimer.Tick += new System.EventHandler(this.HandleTick); fastTimer.Start(); }