Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    168

    C# Calcolare grandezza barra windows

    Salve ragazzi,
    vorrei sapere come e se si può calcolare l'altezza delle barra di windows.
    Perchè io ho una form che è impostata com TopMost,quindi mi va sopra la barra, ma vorrei che ciò non accada.

    Grazie

  2. #2
    Puoi ottenere/impostare i confini dell'area di lavoro (per intenderci, l'area che occupano le finestre massimizzate) con la property DWA.DesktopWorkingArea.
    codice:
    using System;
    using System.Runtime.InteropServices;
    namespace SetDeskWA
    {
    	/// <summary>
    	/// Rectangle used by API functions
    	/// </summary>
    	public struct APIRectangle
    	{
    		public int Left;
    		public int Top;
    		public int Right;
    		public int Bottom;
    		public override string ToString()
    		{
    			return "{Left=" + Left.ToString() + ",Top=" + Top.ToString() + ",Right=" + Right.ToString() + ",Bottom=" + Bottom.ToString() + "}";
    		}
    		public APIRectangle(int Left, int Top, int Right, int Bottom)
    		{
    			this.Left=Left;
    			this.Top=Top;
    			this.Right=Right;
    			this.Bottom=Bottom;
    		}
    	};
    	/// <summary>
    	/// Desktop Working Area routines
    	/// </summary>
    	public static class DWA
    	{
    		private const int SPI_SETWORKAREA = 47;
        	private const int SPI_GETWORKAREA = 48;
    
        	[DllImport("user32.dll")]
        	private static extern bool SystemParametersInfo(int uiAction, int uiParam, ref APIRectangle rect, int fWinIni);
        	public static APIRectangle DesktopWorkingArea
        	{
        		get
        		{
        			APIRectangle WA = new APIRectangle();
        			if(!SystemParametersInfo(SPI_GETWORKAREA,0,ref WA,0))
        				throw new System.ComponentModel.Win32Exception();
        			return WA;
        		}
        		set
        		{
        			if(!SystemParametersInfo(SPI_SETWORKAREA,0,ref value,0))
        				throw new System.ComponentModel.Win32Exception("Used rectangle: " + value.ToString());
        		}
        		
        	}
    	}
    }
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    168
    Originariamente inviato da MItaly
    Puoi ottenere/impostare i confini dell'area di lavoro (per intenderci, l'area che occupano le finestre massimizzate) con la property DWA.DesktopWorkingArea.
    codice:
    using System;
    using System.Runtime.InteropServices;
    namespace SetDeskWA
    {
    	/// <summary>
    	/// Rectangle used by API functions
    	/// </summary>
    	public struct APIRectangle
    	{
    		public int Left;
    		public int Top;
    		public int Right;
    		public int Bottom;
    		public override string ToString()
    		{
    			return "{Left=" + Left.ToString() + ",Top=" + Top.ToString() + ",Right=" + Right.ToString() + ",Bottom=" + Bottom.ToString() + "}";
    		}
    		public APIRectangle(int Left, int Top, int Right, int Bottom)
    		{
    			this.Left=Left;
    			this.Top=Top;
    			this.Right=Right;
    			this.Bottom=Bottom;
    		}
    	};
    	/// <summary>
    	/// Desktop Working Area routines
    	/// </summary>
    	public static class DWA
    	{
    		private const int SPI_SETWORKAREA = 47;
        	private const int SPI_GETWORKAREA = 48;
    
        	[DllImport("user32.dll")]
        	private static extern bool SystemParametersInfo(int uiAction, int uiParam, ref APIRectangle rect, int fWinIni);
        	public static APIRectangle DesktopWorkingArea
        	{
        		get
        		{
        			APIRectangle WA = new APIRectangle();
        			if(!SystemParametersInfo(SPI_GETWORKAREA,0,ref WA,0))
        				throw new System.ComponentModel.Win32Exception();
        			return WA;
        		}
        		set
        		{
        			if(!SystemParametersInfo(SPI_SETWORKAREA,0,ref value,0))
        				throw new System.ComponentModel.Win32Exception("Used rectangle: " + value.ToString());
        		}
        		
        	}
    	}
    }
    Allora cioò è vero e dovrebbe funzionare. Allora io ho la risoluzione dello schermo impostata ha 1680*1050. Il metodo DesktopWorkingArea mi restituisce come valore Bottom 1020. Se io faccio:
    codice:
    Form a = new Form("Main");
    a.TopMost = true;
    a.Size = new Size(320,DWA.DesktopWorkingArea.Bottom);
    a.Show();
    Perchè lui allora ancora copre la barra anche se ho visto che il valore giusto da inserire in modo tale che la form non sovrapponga la barra sia 920?
    Grazie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.