- Практическое руководство. Сохранение файлов с помощью элемента управления RichTextBox в Windows Forms How to: Save Files with the Windows Forms RichTextBox Control
- Сохранение содержимого элемента управления в файле To save the contents of the control to a file
- How do I create an EXE file from Windows Forms? [closed]
- 1 Answer 1
Практическое руководство. Сохранение файлов с помощью элемента управления RichTextBox в Windows Forms How to: Save Files with the Windows Forms RichTextBox Control
RichTextBoxЭлемент управления Windows Forms может записывать отображаемые сведения в одном из следующих форматов: The Windows Forms RichTextBox control can write the information it displays in one of several formats:
с обычным текстом; Plain text
Обычный текст в Юникоде Unicode plain text
Формат Rich-Text (RTF) Rich-Text Format (RTF)
RTF с пробелами вместо объектов OLE RTF with spaces in place of OLE objects
Обычный текст с текстовым представлением объектов OLE Plain text with a textual representation of OLE objects
Чтобы сохранить файл, вызовите SaveFile метод. To save a file, call the SaveFile method. Можно также использовать метод SaveFile для сохранения данных в поток. You can also use the SaveFile method to save data to a stream. Для получения дополнительной информации см. SaveFile(Stream, RichTextBoxStreamType). For more information, see SaveFile(Stream, RichTextBoxStreamType).
Сохранение содержимого элемента управления в файле To save the contents of the control to a file
Определите путь к файлу, который необходимо сохранить. Determine the path of the file to be saved.
Для этого в реальном приложении обычно используется SaveFileDialog компонент. To do this in a real-world application, you would typically use the SaveFileDialog component. Общие сведения см. в разделе Общие сведения о компоненте SaveFileDialog. For an overview, see SaveFileDialog Component Overview.
Вызовите SaveFile метод RichTextBox элемента управления, указав файл для сохранения и, при необходимости, тип файла. Call the SaveFile method of the RichTextBox control, specifying the file to save and optionally a file type. При вызове метода с именем файла в качестве единственного аргумента файл будет сохранен как RTF. If you call the method with a file name as its only argument, the file will be saved as RTF. Чтобы указать другой тип файла, вызовите метод со значением перечисления RichTextBoxStreamType в качестве второго аргумента. To specify another file type, call the method with a value of the RichTextBoxStreamType enumeration as its second argument.
В приведенном ниже примере путь, заданный для расположения RTF-файла, является папкой » Мои документы «. In the example below, the path set for the location of the rich-text file is the My Documents folder. Это расположение используется, поскольку можно предположить, что большинство компьютеров, работающих под управлением операционной системы Windows, будут содержать эту папку. This location is used because you can assume that most computers running the Windows operating system will include this folder. Выбор этого расположения также позволяет пользователям с минимальными уровнями доступа к системе безопасно запускать приложение. Choosing this location also allows users with minimal system access levels to safely run the application. В приведенном ниже примере предполагается, что форма с RichTextBox уже добавленным элементом управления. The example below assumes a form with a RichTextBox control already added.
В этом примере создается файл (если файл отсутствует). This example creates a new file, if the file does not already exist. Если приложению требуется создать файл, этому приложению требуется доступ для создания папки. If an application needs to create a file, that application needs Create access for the folder. Для задания разрешений используются списки управления доступом. Permissions are set using access control lists. Если файл уже существует, приложению требуется только доступ на запись, чем меньше привилегия. If the file already exists, the application needs only Write access, a lesser privilege. Там, где это возможно, более безопасно создавать файл во время развертывания и предоставлять доступ только для чтения к одному файлу, а не к папке. Where possible, it is more secure to create the file during deployment, and only grant Read access to a single file, rather than Create access for a folder. По тем же соображениям рекомендуется записывать данные в пользовательские папки, а не в коревую папку или папку Program Files. Also, it is more secure to write data to user folders than to the root folder or the Program Files folder.
How do I create an EXE file from Windows Forms? [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago .
I have a simple project in C#. It’s a Windows Forms application.
I want to be able to make this into an EXE file to be able to give this out to some of my friends. I am using Visual Studio 2015.
Before you say that there is an application file in the bin/debug folder, yes, I know that. The thing is that I want to be able to create this into just one file where they won’t be able to access the code.
1 Answer 1
Very simple steps:
- Compile the application in Release mode:
- Visual Studio:
- .NET Framework MSBuild: msbuild.exe ConsoleApp1.sln /t:Build /p:Configuration=Release
- .NET Core CLI: dotnet build -c Release (you may need to configure the project to output EXE)
- Open the solution folder
- Open the application project folder
- Open the Bin folder
- Open the Release folder
- Copy the .exe file
- Share it.