Шаг 3. Настройка свойств формы Step 3: Set your form properties
Далее окно Свойства используется для изменения внешнего вида формы. Next, you use the Properties window to change the way your form looks.
Настройка свойств формы How to set your form properties
Убедитесь, что отображается конструктор Windows Forms. Be sure you’re looking at Windows Forms Designer. В интегрированной среде разработки Visual Studio откройте вкладку Form1.cs [Design] (или вкладку Form1.vb [Design] в Visual Basic). In the Visual Studio integrated development environment (IDE), choose the Form1.cs [Design] tab (or the Form1.vb [Design] tab in Visual Basic).
Чтобы выделить форму Form1, щелкните в любом ее месте. Choose anywhere inside the form Form1 to select it. Посмотрите на окно Свойства. Теперь оно должно отображать свойства формы. Look at the Properties window, which should now be showing the properties for the form. У формы есть различные свойства. Forms have various properties. Например, можно установить цвет переднего плана и фона, текст заголовка, который отображается в верхней части формы, размер формы и другие свойства. For example, you can set the foreground and background color, title text that appears at the top of the form, size of the form, and other properties.
Если окно Свойства не открывается, остановите приложение, нажав квадратную кнопку Остановить отладку на панели инструментов, или просто закройте окно. If the Properties window doesn’t appear, stop your app by choosing the square Stop Debugging button on the toolbar, or just close the window. Если приложение остановлено, но окно Свойства все равно не отображается, в строке меню выберите Вид > Окно свойств. If the app is stopped and you still don’t see the Properties window, on the menu bar, choose View > Properties Window.
Когда форма будет выбрана, найдите свойство Text в окне Свойства. After the form is selected, find the Text property in the Properties window. В зависимости от того, как отсортирован список, может потребоваться прокрутить вниз. Depending on how the list is sorted, you might need to scroll down. Выберите Text, введите Программа просмотра изображений, а затем нажмите клавишу ВВОД. Choose Text, type Picture Viewer, and then choose Enter. Теперь форма должна содержать текст Программа просмотра изображений в заголовке окна. Окно Свойства должно выглядеть так, как показано на снимке экрана ниже. Your form should now have the text Picture Viewer in its title bar, and the Properties window should look similar to the following screenshot.
**Окно* _ _»Свойства» **Properties* _ _window
Свойства можно упорядочить по категориям или в алфавитном порядке. Properties can be ordered by a Categorized or Alphabetical view. Вы можете переключаться между двумя этими представлениями с помощью кнопок в окне Свойства. You can switch between these two views by using the buttons on the Properties window. В этом руководстве свойства легче находить в представлении, в котором свойства представлены в алфавитном порядке. In this tutorial, it’s easier to find properties through the Alphabetical view.
Вернитесь к конструктору Windows Forms. Go back to Windows Forms Designer. Нажмите нижний правый маркер перетаскивания формы, который представляет собой небольшой белый квадрат в нижнем правом углу формы и показан на рисунке ниже. Choose the form’s lower-right drag handle, which is the small white square in the lower-right of the form and appears as follows.
Маркер перетаскивания Drag handle
Перетащите маркер, чтобы изменить размер формы — она должна стать шире и немного выше. Drag the handle to resize the form so the form is wider and a bit taller.
Посмотрите в окно Свойства и обратите внимание, что изменилось значение свойства Size. Look at the Properties window, and notice that the Size property has changed. Свойство Size меняется при каждом изменении формы. The Size property changes each time you resize the form. Перетащите маркер, чтобы форма имела размер около 550, 350 (не обязательно точно такие значения). Такой размер вполне подходит для этого проекта. Try dragging the form’s handle to resize it to a form size of approximately 550, 350 (no need to be exact), which should work well for this project. В качестве альтернативы можно вводить значения непосредственно в свойстве Size и затем нажимать клавишу ВВОД. As an alternative, you can enter the values directly in the Size property and then choose the Enter key.
Запустите приложение еще раз. Run your app again. Помните, что для запуска приложения можно использовать любой из описанных ниже методов. Remember, you can use any of the following methods to run your app.
Нажмите клавишу F5. Choose the F5 key.
В строке меню выберите Отладка > Начать отладку. On the menu bar, choose Debug > Start Debugging.
На панели инструментов нажмите кнопку Начать отладку, которая показана на рисунке ниже. On the toolbar, choose the Start Debugging button, which appears as follows.
**Кнопка «Начать отладку»* _ _на панели инструментов* **Start Debugging* _ _toolbar button*
Как и ранее, интегрированная среда разработки выполняет сборку приложения и запускает его, после чего открывается окно. Just like before, the IDE builds and runs your app, and a window appears.
Перед переходом к следующему шагу остановите приложение, так как интегрированная среда разработки не позволяет изменять выполняющееся приложение. Before going to the next step, stop your app, because the IDE won’t let you change your app while it’s running. Помните, что для остановки приложения можно использовать любой из описанных ниже методов. Remember, you can use any of the following methods to stop your app.
На панели инструментов нажмите кнопку Остановить отладку. On the toolbar, choose the Stop Debugging button.
В строке меню выберите Отладка > Остановить отладку. On the menu bar, choose Debug > Stop Debugging.
На клавиатуре нажмите клавиши SHIFT+F5. Use your keyboard and press Shift+F5.
Нажмите кнопку X в верхнем углу окна Программа просмотра изображений. Choose the X button in the upper corner of the Picture Viewer window.
Дальнейшие действия Next steps
Предыдущий раздел руководства: Шаг 2. Запуск приложения для просмотра изображений. To return to the previous tutorial step, see Step 2: Run your picture viewer app.
Windows forms are you sure
Are You Sure? — A light «dirty forms» JQuery Plugin
Version: 1.9
Are-you-sure ( jquery.are-you-sure.js ) is simple light-weight «dirty form» JQuery Plugin for modern browsers. It helps prevent users from losing unsaved HTML Form changes by promoting the user to save/submit.
It’s simple to use. Just add the following line to your page’s ready function:
Are-you-sure is a minimal plugin for modern browsers. There are plenty of «dirty forms» implementations out there, however they all seemed very heavyweight and over-engineered. Most were written some time back and contain many ‘hacks’ to support legacy browsers, and/or rely on other fat dependencies such as FaceBox or jQueryUI. Are-you-sure solves this by doing this simple task in the simplest possible way.
Are-you-sure is as simple as it gets:
- 100% JS with zero dependencies and no external CSS.
- Leverages onBeforeUnload to detect all page/browser exit events.
- Works on forms of any size.
- Correct state management — if a user edits then restores a value, the form is not considered dirty.
- Easy to understand — less than a «terminal screen» of code!
- Graceful degradation on legacy browsers (i.e. if you’re running an old browser. remember to save 🙂
To ignore selected fields from the dirtyness check:
The demo page shows the advanced usage options in more detail.
Are-You-Sure is a light-weight jQuery plugin — it’s a single standalone JavaScript file. You can download the jquery.are-you-sure.js file and include it in your page. Because it’s so simple it seems a shame to add an extra browser round trip. It’s recommended that you consider concatenating it with other common JS lib files, and/or even cut-n-pasting the code (and license header) into one of your existing JS files.
For experimental Mobile Safari support, also include ays-beforeunload-shim.js (see Known Issues below).
Are-you-sure may also be installed with Bower:
If you’re using, or like, Are-you-sure make sure you star/watch this project so you can stay up-to-date with updates.
This demo page hosts a number of example forms.
Are-you-sure has been tested on and fully supports the following browsers:
- IE 9 through 11
- Google Chrome (versions since 2012)
- Firefox (versions since 2012)
- Safari (versions since 2012)
Experimental support is available on iOS and Opera via the beforeunload shim (see below).
Known Issues & Limitations
Mobile Safari and Opera
The windows.beforeunload event is not supported on iOS (iPhone, iPad, and iPod). An experimental shim offering partial beforeunload emulation is provided to help plug this gap. It works by scanning the page for anchor links and augments the default behaviour to first check with Are-you-sure before navigating away. To use, simply include ays-beforeunload-shim.js in your page.
The custom message option may not work on Firefox (Firefox bug 588292).
The aim is to keep Are-you-sure simple and light. If you think you have a good idea which is aligned with this objective, please voice your thoughts in the issues list.
If possible, please submit your pull request against the most recent dev-* branch rather than master. This will make it easier to merge your code into the next planned release.
2014-08-13 (1.9) — This is a minor bugfix release:
- Addressed issue #45 seen with empty select fields.
- Thanks valgen and tus124 for the contribution.
2014-06-22 (1.8) — This is a minor bugfix release:
- Fixed NPE that may occur when using a ‘multiple’ option field.
- Minor timing tweak to help mitigate bypass issue raised in #45
- Thanks apassant and amatenkov for the contribution.
2014-05-28 (1.7)
- Fixed multiple warning dialogs that may appear on IE and recent versions of Chrome
- Experimental support for iOS Mobile Safari (via a beforeunload shim)
- Various minor fixes (e.g. support input fields with no type=)
- Minor performance improvements on pages with multiple forms
- Improved documentation and examples
- Thanks to lfjeff and aqlong for the contribution and ideas!
2014-02-07 (1.6)
- Add field count tracking ( addRemoveFieldsMarksDirty ) (contrib jonegerton)
- Added event to manually trigger a form check/recheck (contrib jonegerton)
- Thanks to jonegerton for the contribution!
2013-11-15 (1.5)
- Added support for HTML5 input field types. (contrib albinsunnanbo)
- New option to reinitialize/reset the dirty state. This is handy if you’re managing your own async submit/save using AJAX. (contrib albinsunnanbo)
- Thanks to albinsunnanbo for the contribution!
2013-10-2 (1.4)
- Added dirty and clean «events»
- Added an option to disable the message (dirty tracking only)
- Added an option to rescan a form to look/detect any new fields
2013-07-24 — Minor fix — don’t fail if form elements have no «name» attribute.
2013-05-14 — Added support for form reset buttons (contributed by codev).
2013-05-01 — Added support for hidden and disabled form fields.
2013-02-03 — Add demo page.
2013-01-28 — Add change event support and a demo page.
2012-10-26 — Use dashes in class names rather than camel case.
2012-10-24 — Initial public release.
jQuery version 1.4.2 or higher. 2.0+ or 1.10+ recommended.
Can’t use System.Windows.Forms
I have tried making (my first) a C# program:
This goes well, but if I try using System.Windows.Forms:
This is the error I get:
Some details: — I am using Visual Studio 2012; — I have installed the .NET Development Kit; — It is a Console Application.
Maybe it’s because on a Console Application can’t use System.Windows.Forms? If so, what program should be? I also have tried with a form, but I was only displaying a window and no code.
8 Answers 8
A console application does not automatically add a reference to System.Windows.Forms.dll.
Right-click your project in Solution Explorer and select Add reference. and then find System.Windows.Forms and add it.
You have to add the reference of the namespace : System.Windows.Forms to your project, because for some reason it is not already added, so you can add New Reference from Visual Studio menu.
Right click on «Reference» ▶ «Add New Reference» ▶ «System.Windows.Forms»
To add the reference to «System.Windows.Forms», it seems to be a little different for Visual Studio Community 2017.
1) Go to solution explorer and select references
2) Right-click and select Add references