当前位置: 首页>>代码示例>>C#>>正文


C# System.Drawing.Rectangle.ToString方法代码示例

本文整理汇总了C#中System.Drawing.Rectangle.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Rectangle.ToString方法的具体用法?C# System.Drawing.Rectangle.ToString怎么用?C# System.Drawing.Rectangle.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Rectangle的用法示例。


在下文中一共展示了System.Drawing.Rectangle.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseCommandLineAndLaunch

        static void ParseCommandLineAndLaunch(string[] mainArgs)
        {
            Logging.LogLineIf(fDebugTrace, "ParseCommandLineAndLaunch() entered.");

            IntPtr hWnd = IntPtr.Zero;
            string launchString = M_SCREENSAVER;
            int lastProcessedIndex = -1;

            // first argument must be /scr
            if ((mainArgs.Length > 0) && (mainArgs[0].ToLowerInvariant() != @"/scr"))
            {
                throw new ArgumentException(@"CommandLine: /scr can only be the first argument." +
                Environment.NewLine + Environment.CommandLine);
            }
            lastProcessedIndex = 0;

            // second arg must be one of four valid /scr-related arguments
            if ((mainArgs.Length > 1) && !scrArgs.Contains(mainArgs[1].ToLowerInvariant()))
            {
                throw new ArgumentException(@"CommandLine: /scr can only be followed by a valid /scr-related argument." +
                Environment.NewLine + Environment.CommandLine);
            }
            lastProcessedIndex = 1;

            // if second arg starts with cp_ it must be followed with a valid window handle
            if (mainArgs[1].ToLowerInvariant() == M_CP_CONFIGURE || mainArgs[1].ToLowerInvariant() == M_CP_MINIPREVIEW)
            {
                if ((mainArgs.Length > 2) && mainArgs[2].ToLowerInvariant().StartsWith("-"))
                {
                    string subArg = mainArgs[2].ToLowerInvariant();
                    string longCandidate = subArg.Substring(1);
                    if (!String.IsNullOrEmpty(longCandidate))
                    {
                        long val;
                        bool worked = long.TryParse(longCandidate, out val);
                        if (worked)
                        {
                            Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): passed hWnd was " + DecNHex(val));

                            hWnd = new IntPtr(val);
                        }
                        else  // bad parse
                        {
                            throw new ArgumentException(@"CommandLine: invalid window handle passed: " + longCandidate +
                                Environment.NewLine + Environment.CommandLine);
                        }
                    }
                    else   // null or empty
                    {
                        throw new ArgumentException(@"CommandLine: invalid window handle passed." +
                            Environment.NewLine + Environment.CommandLine);
                    }
                }
                else  // missing required sub argument
                {
                    throw new ArgumentException(@"CommandLine: /cp_ argument missing required subargument." +
                        Environment.NewLine + Environment.CommandLine);
                }
                lastProcessedIndex = 2;
            }

            // by this point, our mode is in mainArgs[1] and hWnd is either IntPtr.Zero or a numerically validated hWnd.
            launchString = mainArgs[1].ToLowerInvariant();

            // launch
            if (launchString == M_CP_MINIPREVIEW)
            {
                Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): target form is CPPreview.");
                Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): calling new CP_Preview("+ DecNHex(hWnd) +")...");
                CP_Preview preview = new CP_Preview(hWnd);
                Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): Constructor returned. Window handle is: " + DecNHex(preview.Handle));

                int error = 0;

                // Determine what the initial parent of our form is.
                Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): Getting initial value of parent: Calling GetParent(" + DecNHex(preview.Handle) + ")...");
                NativeMethods.SetLastErrorEx(0, 0);
                IntPtr originalParent = NativeMethods.GetParent(preview.Handle);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): GetParent() returned IntPtr = " + DecNHex(originalParent));
                Logging.LogLineIf(fDebugTrace, "      GetLastError() returned: " + error.ToString());
                Logging.LogLineIf(fDebugTrace, " ");

                // Set the passed hWnd to be the parent of the form window.
                Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): Changing parent to passed hWnd: Calling SetParent(" + DecNHex(preview.Handle) + ", " + DecNHex(hWnd) + ")...");
                NativeMethods.SetLastErrorEx(0, 0);
                IntPtr newParent = NativeMethods.SetParent(preview.Handle, hWnd);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): SetParent() returned IntPtr = " + DecNHex(newParent));
                Logging.LogLineIf(fDebugTrace, "      GetLastError() returned: " + error.ToString());
                Logging.LogLineIf(fDebugTrace, " ");

                // Verify if the form now has the expected new parent.
                Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): Verifying new parent: Calling GetParent(" + DecNHex(preview.Handle) + ")...");
                NativeMethods.SetLastErrorEx(0, 0);
                IntPtr verifyParent = NativeMethods.GetParent(preview.Handle);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Logging.LogLineIf(fDebugTrace, "  ParseCommandLineAndLaunch(): GetParent() returned IntPtr = " + DecNHex(verifyParent));
                Logging.LogLineIf(fDebugTrace, "      GetLastError() returned: " + error.ToString());
                Logging.LogLineIf(fDebugTrace, " ");
//.........这里部分代码省略.........
开发者ID:joethegitter,项目名称:ScotSoft,代码行数:101,代码来源:EntryPoint.cs

示例2: ShowPreview

        /// <summary>
        /// Show our Preview user control in the little window provided by the Screen Saver control panel.
        /// </summary>
        /// <param name="hWnd">The hWnd passed to us by the Screen Saver control panel.</param>
        private void ShowPreview(IntPtr hWnd)
        {
            Log("ShowPreview(): Entered.");
            Log("   ShowPreview(): cpl hWnd passed to us = " + hWnd);

            if (NativeMethods.IsWindow(hWnd))
            {
                // Get the rect of the desired parent
                int error = 0;
                System.Drawing.Rectangle ParentRect = new System.Drawing.Rectangle();
                NativeMethods.SetLastErrorEx(0, 0);
                Log("  ShowPreview(): Let's Get the ClientRect of that puppy:");
                Log("  ShowPreview(): Calling GetClientRect(" + hWnd + ")...");
                bool fSuccess = NativeMethods.GetClientRect(hWnd, ref ParentRect);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Log("  ShowPreview(): GetClientRect() returned bool = " + fSuccess + ", rect = " + ParentRect.ToString());
                Log("      GetLastError() returned: " + error.ToString());
                Log(" ");

                // Create the HwndSource which will host our Preview user control
                Log("  ShowPreview(): Let's build a new HwndSource (src), and attach it to the cpl window:");
                HwndSourceParameters parameters = new HwndSourceParameters();
                parameters.WindowStyle = NativeMethods.WindowStyles.WS_CHILD | NativeMethods.WindowStyles.WS_VISIBLE;
                parameters.SetPosition(0, 0);  // in theory, our child will use values relative to parents position
                parameters.SetSize(ParentRect.Width, ParentRect.Height);
                parameters.ParentWindow = hWnd;
                HwndSource src = new HwndSource(parameters);

            #if DEBUG
                // Let's see what Windows thinks
                Log("  ShowPreview(): Attached it. Let's see what Windows thinks:");
                Log("  ShowPreview(): Calling GetParent(src.Handle)...");
                NativeMethods.SetLastErrorEx(0, 0);
                IntPtr handle = IntPtr.Zero;
                handle = NativeMethods.GetParent(src.Handle);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Log("  ShowPreview(): GetParent() returned: " + handle.ToString());
                Log("      GetLastError() returned: " + error.ToString());
                Log(" ");
            #endif

                // Create the user control and attach it
                Log("  ShowPreview(): Creating the user control (Preview)");
                PreviewControl Preview = new PreviewControl();
                Log("  ShowPreview(): setting src.RootVisual to user control...");
                src.RootVisual = Preview;
                Preview.Visibility = Visibility.Visible;

            #if DEBUG
                // Let's find out what Windows thinks
                Log("  ShowPreview(): Set it. Let's see what Windows thinks the HwndSource for Preview is:");
                HwndSource hs = (HwndSource)HwndSource.FromVisual(Preview);
                Log("  ShowPreview(): HwndSource.FromVisual(Preview) is: " + HwndSource.FromVisual(Preview));
                Log("  ShowPreview(): Let's see what Windows thinks the parent hWnd of Preview is:");
                Log("  ShowPreview(): Calling GetParent((HwndSource)HwndSource.FromVisual(Preview).handle)...");
                NativeMethods.SetLastErrorEx(0, 0);
                IntPtr ucHandle = IntPtr.Zero;
                handle = NativeMethods.GetParent(hs.Handle);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Log("  ShowPreview(): GetParent() returned: " + handle.ToString());
                Log("      GetLastError() returned: " + error.ToString());
                Log(" ");

                Log("  ShowPreview(): Is the src window visible?");
                Log("  ShowPreview(): Calling IsWindowVisible(src.Handle)...");
                NativeMethods.SetLastErrorEx(0, 0);
                bool fVisible = NativeMethods.IsWindowVisible(src.Handle);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Log("  ShowPreview(): IsWindowVisible() returned: " + fVisible.ToString());
                Log("      GetLastError() returned: " + error.ToString());
                Log(" ");
            #endif

                // Let's hook into src's message pump
                Log("  ShowPreview(): Let's hook into src's message pump");
                // TODO: determine if we need to hook into message pump

            }
            else
            {
                Log("  ShowPreview(): Invalid hWnd passed: " + hWnd.ToString());
                throw new ArgumentException("Invalid hWnd passed to ShowPreview(): " + hWnd.ToString());
            }

            Log("ShowPreview(): exiting.");
        }
开发者ID:joethegitter,项目名称:SchackMediaViewer,代码行数:90,代码来源:OpenTheWindows.cs

示例3: ShowMiniPreview

        /// <summary>
        /// Show the little miniControlPanelForm in the Control Panel window
        /// </summary>
        /// <param name="hWnd">hwnd to the little window of the control panel.</param>
        static void ShowMiniPreview(IntPtr hWnd)
        {
            Logging.LogLineIf(fDebugTrace, "ShowMiniPreview(): Entered.");
            Logging.LogLineIf(fDebugTrace, "   ShowMiniPreview(): hWnd = " + Logging.DecNHex(hWnd));

            if (NativeMethods.IsWindow(hWnd))
            {
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): calling miniControlPanelForm constructor with argument: " + Logging.DecNHex(hWnd) + " ...");
                miniControlPanelForm preview = new miniControlPanelForm(hWnd);
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): Constructor returned. Window handle is: " + Logging.DecNHex(preview.Handle));

                int error = 0;

                // Use Win32 API's to connect our little form to the Control Panel window handles

                //// Determine who the initial parent of our form is.
                //Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): Getting initial parent of form: Calling GetParent(" + Logging.DecNHex(preview.Handle) + ")...");
                //NativeMethods.SetLastErrorEx(0, 0);
                //IntPtr originalParent = NativeMethods.GetParent(preview.Handle);
                //error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                //Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): GetParent() returned IntPtr = " + Logging.DecNHex(originalParent));
                //Logging.LogLineIf(fDebugTrace, "      GetLastError() returned: " + error.ToString());
                //Logging.LogLineIf(fDebugTrace, " ");

                // Set the passed hWnd to be the parent of the form window.
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): Changing parent of form to passed hWnd: Calling SetParent(" + Logging.DecNHex(preview.Handle) + ", " + Logging.DecNHex(hWnd) + ")...");
                NativeMethods.SetLastErrorEx(0, 0);
                IntPtr newParent = NativeMethods.SetParent(preview.Handle, hWnd);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): SetParent() returned IntPtr = " + Logging.DecNHex(newParent));
                Logging.LogLineIf(fDebugTrace, "      GetLastError() returned: " + error.ToString());
                Logging.LogLineIf(fDebugTrace, " ");

                // Verify that the form now has the expected new parent.
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): Verifying new parent: Calling GetParent(" + Logging.DecNHex(preview.Handle) + ")...");
                NativeMethods.SetLastErrorEx(0, 0);
                IntPtr verifyParent = NativeMethods.GetParent(preview.Handle);
                error = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): GetParent() returned IntPtr = " + Logging.DecNHex(verifyParent));
                Logging.LogLineIf(fDebugTrace, "      GetLastError() returned: " + error.ToString());
                Logging.LogLineIf(fDebugTrace, " ");

                // Set the size of the form to the size of the parent window (using the passed hWnd).
                // Get the rect
                System.Drawing.Rectangle ParentRect = new System.Drawing.Rectangle();
                NativeMethods.SetLastErrorEx(0, 0);
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): Calling GetClientRect(" + Logging.DecNHex(hWnd) + ")...");
                bool fSuccess = NativeMethods.GetClientRect(hWnd, ref ParentRect);
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): GetClientRect() returned bool = " + fSuccess + ", rect = " + ParentRect.ToString());
                Logging.LogLineIf(fDebugTrace, "      GetLastError() returned: " + error.ToString());
                Logging.LogLineIf(fDebugTrace, " ");

                // Set our size to new rect and location at (0, 0)
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): Setting Size and Position with C# code:");
                preview.Size = ParentRect.Size;
                preview.Location = new System.Drawing.Point(0, 0);

                // Show the form
                Logging.LogLineIf(fDebugTrace, " ");
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): Calling preview.Show()...");
                preview.Show();
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): Show() has returned.");

                // and run it
                Logging.LogLineIf(fDebugTrace, "  ShowMiniPreview(): calling Application.Run(preview)).");
                Application.Run(preview);
            }
            else
            {
                Logging.LogLineIf(fDebugOutput, "  ShowMiniPreview(): Invalid hWnd passed: " + hWnd.ToString());
                throw new ArgumentException("Invalid hWnd passed to ShowMiniPreview(): " + hWnd.ToString());
            }

            Logging.LogLineIf(fDebugTrace, "ShowMiniPreview(): Exiting.");
        }
开发者ID:joethegitter,项目名称:ScotSoft,代码行数:79,代码来源:EntryPoint.cs


注:本文中的System.Drawing.Rectangle.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。