Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
U

User 12768383

@User 12768383
About
Posts
7
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Code to move window not working.
    U User 12768383

    Oh i think the problem is that sometimes the window is created partially outside the screen resolution and for some reason the if statements make the window start vibrating because it's constantly changing directions. So to fix the problem i need to make sure that the window isn't created outside of the screen. I changed a few things and it seemed to fix a majority of the problems:

    WindowX = (random.Next(0, width - Width));
    WindowY = (random.Next(0, height - Height));

            this.Left += WindowVx;
            if (Left < 0 || (Left + this.Width) > width){
                WindowVx = -WindowVx;
            } 
    
    
            this.Top += WindowVy;
            if (Top < 0 || (Top + this.Height) > height) {
                WindowVy = -WindowVy;
            } 
    

    However sometimes the window is still created a bit past the bounds for some reason, but I'll work on it tomorrow, for now i need to sleep. Thank you for the help so far though! Oh, and for screen object, do you mean this?:

        private int width = Screen.PrimaryScreen.WorkingArea.Width;
        private int height = Screen.PrimaryScreen.WorkingArea.Height;
    

    I changed it to this:

        private int width = Screen.PrimaryScreen.Bounds.Width;
        private int height = Screen.PrimaryScreen.Bounds.Height;
    

    That way it'll go over my task bar.

    C# csharp linq graphics question lounge

  • Code to move window not working.
    U User 12768383

    When you say move the form do you mean the things inside the window? I'm trying to move the entire window and by information on sizing do you mean my screen resolution? If i use Left, Width, and Top, and the Window Client Area to move the thing inside the window, do i need something else to move the window itself? Edit: Oh i just looked it up and form is the window itself.

    C# csharp linq graphics question lounge

  • Code to move window not working.
    U User 12768383

    I checked and the width is 282 i think. And by debugger you mean like the play button on xamarin studio? That's what i've been using to test my program. Also just in case i'll post the rest of my form information.

            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(282, 253);
            this.ControlBox = false;
            this.Controls.Add(this.webBrowser1);
            this.KeyPreview = true;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "Form1";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.Text = "test";
            this.TopMost = true;
            this.ResumeLayout(false);
    
    C# csharp linq graphics question lounge

  • Code to move window not working.
    U User 12768383

    Hm... for some reason the window just moves back and forth kind of like it's vibrating. I'm not really sure what's causing it as the code without the if statement works fine. This is the code right now:

            this.Left += WindowVx;
            if (Left < 0 || (Left + this.Width) > ClientSize.Width){
                WindowVx = -WindowVx;
            }
    
    C# csharp linq graphics question lounge

  • Code to move window not working.
    U User 12768383

    Ok, I've gotten it to move horizontally, vertically and diagonally fine so i've added boundaries so that it can't move past the screen limits. However when i added that it just shakes back and forth. From what i understand it first increases the x co-ordinates, moving the window to the right. Then the if statement checks if it has gone past the left of the screen and if it has it will reverse the direction the window moves. The second if statement checks that x co-ordinates including the width of the window doesn't past the width of the screen. Is this all correct?

    private void timer4_Tick (object sender, EventArgs e)
    {
    this.Left += WindowVx;
    if (this.Left < 0) {
    WindowVx = -WindowVx;
    }
    if (this.Left + this.Width > ClientSize.Width) {
    WindowVx = -WindowVx;
    }
    this.Refresh ();
    }

    C# csharp linq graphics question lounge

  • Code to move window not working.
    U User 12768383

    Oh thank you! I got it working now!

    C# csharp linq graphics question lounge

  • Code to move window not working.
    U User 12768383

    I'm trying to get a window to move along the x axis however currently the code(timer4_tick) that i have is having no effect. Is there something that i am missing? I'll try to post only the code that is relevant.

    //This is in my form1.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    public partial class Form1 : Form
    {
    private int WindowVx, WindowVy;
    private int WindowX, WindowY;
    private int width = Screen.PrimaryScreen.WorkingArea.Width;
    private int height = Screen.PrimaryScreen.WorkingArea.Height;

    private void timer1_Tick(object sender, EventArgs e)
    {

            WindowX = random.Next(width);
            WindowY = random.Next(height);
            int wx = random.Next(width / 2);
            int wy = random.Next(height / 2);
            WindowVx = random.Next (1, 4);
            WindowVy = random.Next (1, 4);
            this.Left = WindowX;
            this.Top = WindowY;
            this.Width = wx;
            this.Height = wx;
            //form.Show();
            //new Form1().Show();
    
        }
    

    private void timer4_Tick (object sender, EventArgs e)
    {
    WindowX += WindowVx;
    if (WindowX < 0) {
    WindowVx = -WindowVx;
    } else if (WindowX + width > ClientSize.Width) {
    WindowVx = -WindowVx;
    }

            this.Refresh ();
        }
    

    //The following part is in form1.designer.cs

    this.timer4 = new System.Windows.Forms.Timer (this.components);

            this.timer4.Enabled = true;
            this.timer4.Interval = 1000;
            this.timer4.Tick += new System.EventHandler (this.timer4\_Tick);
    
        private System.Windows.Forms.Timer timer4;
    
    C# csharp linq graphics question lounge
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups