private void button1_MouseDown(object sender, MouseEventArgs e) { //Form form = new Form(); _sliderForm = new SliderForm(); //form.Size _sliderForm.Visible = false; _sliderForm.Slider.Min = this._min; _sliderForm.Slider.Max = this._max; _sliderForm.Slider.StepSize = this._stepSize; _sliderForm.Slider.Value = this._value; this._ptMouseStart = Cursor.Position; _sliderForm.Show(); _sliderForm.Width = 12; _sliderForm.Height = 200; float val = Convert.ToSingle(this.textBox1.Text); //if (Math.Abs(this._uiMax) > 0.001f || Math.Abs(this._uiMin) > 0.001f) // val = (this._value - this._uiMin) / (this._uiMax - this._uiMin); //_sliderForm.Slider.Value = val; Point loc = _sliderForm.Slider.ValueToCenterLoc(_sliderForm.Slider.Value); Point diffSliderToForm = new Point(loc.X - _sliderForm.Location.X, loc.Y - _sliderForm.Location.Y); _sliderForm.Location = new Point(_ptMouseStart.X - diffSliderToForm.X, _ptMouseStart.Y - diffSliderToForm.Y); Rectangle screenRect = Screen.PrimaryScreen.WorkingArea; int diff = _sliderForm.Bottom - screenRect.Bottom; if (diff > 0) { _sliderForm.Top -= diff; } diff = _sliderForm.Top - screenRect.Top; if (diff < 0) { _sliderForm.Top -= diff; } //TODO: how to keep it from appearing quickly in the start position? Right now, start location is -50: ugly but it works _sliderForm.Visible = true; _sliderForm.Slider.ValueChanged += new EventHandler(Slider_ChangedValue); _sliderForm.CloseOnMouseUp = true; _sliderForm.Disposed += new EventHandler(_sliderForm_Disposed); Cursor.Position = _sliderForm.Slider.ValueToCenterLoc(_sliderForm.Slider.Value); _sliderForm.Slider.FakeMouse(); //_sliderForm.Slider.Dragging = true; //form.Controls.Add(slider); //form.ShowDialog(); }
private void button1_MouseDown(object sender, MouseEventArgs e) { //Form form = new Form(); _sliderForm = new SliderForm(); //form.Size _sliderForm.Visible = false; _sliderForm.Slider.Min = this._min; _sliderForm.Slider.Max = this._max; _sliderForm.Slider.StepSize = this._stepSize; _sliderForm.Slider.Value = this._value; this._ptMouseStart = Cursor.Position; _sliderForm.Show(); _sliderForm.Width = 12; _sliderForm.Height = 200; float val = Convert.ToSingle(this.textBox1.Text); //if (Math.Abs(this._uiMax) > 0.001f || Math.Abs(this._uiMin) > 0.001f) // val = (this._value - this._uiMin) / (this._uiMax - this._uiMin); //_sliderForm.Slider.Value = val; Point loc = _sliderForm.Slider.ValueToCenterLoc(_sliderForm.Slider.Value); Point diffSliderToForm = new Point(loc.X - _sliderForm.Location.X, loc.Y - _sliderForm.Location.Y); _sliderForm.Location = new Point(_ptMouseStart.X - diffSliderToForm.X, _ptMouseStart.Y - diffSliderToForm.Y); Rectangle screenRect = Screen.PrimaryScreen.WorkingArea; int diff = _sliderForm.Bottom - screenRect.Bottom; if (diff > 0) _sliderForm.Top -= diff; diff = _sliderForm.Top - screenRect.Top; if (diff < 0) _sliderForm.Top -= diff; //TODO: how to keep it from appearing quickly in the start position? Right now, start location is -50: ugly but it works _sliderForm.Visible = true; _sliderForm.Slider.ValueChanged += new EventHandler(Slider_ChangedValue); _sliderForm.CloseOnMouseUp = true; _sliderForm.Disposed += new EventHandler(_sliderForm_Disposed); Cursor.Position = _sliderForm.Slider.ValueToCenterLoc(_sliderForm.Slider.Value); _sliderForm.Slider.FakeMouse(); //_sliderForm.Slider.Dragging = true; //form.Controls.Add(slider); //form.ShowDialog(); }