我的程序:只有一个文本框.我正在使用C#语言编写代码.
我的目标:在文本框中显示文字/水印:'请输入你的名字'.因此,当用户点击文本框时,默认文本/水印会被清除/删除,以便用户可以在文本框中输入他的名字.
我的问题:我尝试了各种在线可用的代码,但它们似乎都不适合我.所以,我想我应该在这里问一个简单的代码.我在网上找到了一个代码,但似乎不起作用:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SetWatermark("Enter a text here...");
}
private void SetWatermark(string watermark)
{
textBox1.Watermark = watermark;
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
错误1'System.Windows.Forms.TextBox'不包含'Watermark'的定义,并且没有扩展方法'Watermark'接受类型'System.Windows.Forms.TextBox'的第一个参数可以找到(你错过了吗?使用指令或程序集引用?)
如果您对我的目标有任何其他建议,我将非常感激.我在网上累了很多例子,但都很混乱/不工作.感谢您的帮助.:)
我的程序:包含一个包含少量文本框和一个按钮的表单."默认打印机" 在我的计算机上设置为Adobe PDF.
我的目标:当用户点击"打印"按钮时,想要截取表单/ usercontrol的屏幕截图.然后屏幕截图以.pdf格式保存在桌面上.
我的问题:我在代码中遇到两个问题:
问题1:程序捕获的屏幕截图在打印时不适合页面.

我希望截图图像在.pdf的一页上适合这样:

码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Text = "Print Form";
button1.Click += new EventHandler(button1_Click);
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
this.Controls.Add(button1);
}
private void button1_Click(object sender, EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
Bitmap memoryImage;
private void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics …Run Code Online (Sandbox Code Playgroud) 我的程序:检查Settings.txt文件.如果文件不存在,请创建文本并自动写入.如果Settings.txt文件已存在,请忽略.不要在现有文件中创建或写入.
我的问题:当文件不存在时,Settings.txt文件会创建,但它是空的.我希望程序在创建文件时写入.谢谢你的帮助.
private void Form1_Load(object sender, EventArgs e)
{
string path = @"C:\Users\Smith\Documents\Visual Studio 2010\Projects\Ver.2\Settings.txt";
if (!File.Exists(path))
{
File.Create(path);
TextWriter tw = new StreamWriter(path);
tw.WriteLine("Manual Numbers=");
tw.WriteLine("");
tw.WriteLine("Installation Technical Manual: ");
tw.WriteLine("Performance Manual: ");
tw.WriteLine("Planned Maintenance Technical Manual: ");
tw.WriteLine("Service Calibration Manual: ");
tw.WriteLine("System Information Manual: ");
tw.WriteLine("");
tw.Close();
}
}
Run Code Online (Sandbox Code Playgroud) 我的程序包含一个表单和七个用户控件.我正在使用MS Visual Studio 2010 C#语言.
我的程序:将.txt文件中的所有文本显示在UserControl的文本框中.
我的目标:我想检查.txt文件是否存在.如果.txt文件不存在,请创建它,以便用户可以将一些数据放入.txt文件中,然后显示在UserControl的文本框中.如果.txt文件已存在,则直接将.txt文件中的数据显示到文本框中.
我在FORM中检查文件是否存在的代码:
private void Form1_Load(object sender, EventArgs e)
{
string path1 = @"C:\Users\PK\Documents\Visual Studio 2010\ABC.txt";
if (!File.Exists(path1))
{
File.Create(path1);
}
string path2 = @"C:\Users\PK\Documents\Visual Studio 2010\DEF.txt";
if (!File.Exists(path2))
{
File.Create(path2);
}
string path3 = @"C:\Users\PK\Documents\Visual Studio 2010\GHI.txt";
if (!File.Exists(path3))
{
File.Create(path3);
}
string path4 = @"C:\Users\PK\Documents\Visual Studio 2010\JLK.txt";
if (!File.Exists(path4))
{
File.Create(path4);
}
string path5 = @"C:\Users\PK\Documents\Visual Studio 2010\MNO.txt";
if (!File.Exists(path5))
{
File.Create(path5);
}
}
Run Code Online (Sandbox Code Playgroud)
用于将文本从.txt文件读取到UserControl中的TextBox的代码:(对于剩余的6个用户控件及其文本框,这是相同的.只有.txt文件和文本框的名称相应地不同.
private void UserControl1_Load(object sender, EventArgs e) …Run Code Online (Sandbox Code Playgroud) 我的程序:从用户那里获取有关个人详细信息的输入,然后输出信息.
我的问题:程序无法计算位数作为电话号码字段的输入.它接受超过10位数作为电话号码的输入.
我的目标:检查"电话号码"的输入并确保该号码为10位数.
我的代码:
#include <iostream>
#include <string>
#include <limits>
using namespace std;
class Personal_Details
{
public:
void setFirstName (string newFirstName);
void setLastName (string newLastName);
void setBirthdate (int newBirthday);
void setEMail (string newEMail);
void setPhoneNumber (int newPhoneNumber);
void QUESTIONS();
string getFirstName();
string getLastName();
string getEMail();
int getPhoneNumber();
int getBirthdate();
private:
string FirstName;
string LastName;
string EMail;
int PhoneNumber;
int Birthdate;
};
void Personal_Details :: setFirstName (string newFirstName)
{
FirstName = newFirstName;
}
void Personal_Details :: setLastName …Run Code Online (Sandbox Code Playgroud) 我的目标:我希望文本框接受像123.45或0.45或1004.72这样的十进制数字.如果用户键入a或b或c之类的字母,程序应显示一条消息,提醒用户只输入数字.
我的问题:我的代码只检查1003或567或1之类的数字.它不检查像123.45或0.45这样的十进制数字.如何让文本框检查十进制数?以下是我的代码:
namespace Error_Testing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
string tString = textBox1.Text;
if (tString.Trim() == "") return;
for (int i = 0; i < tString.Length; i++)
{
if (!char.IsNumber(tString[i]))
{
MessageBox.Show("Please enter a valid number");
return;
}
}
//If it get's here it's a valid number
}
}
}
Run Code Online (Sandbox Code Playgroud)
我是新手,并提前感谢您的帮助.:)
我的部分代码:
double function (double x)
{
f = x^5-3*x^4+3*x^3-2*x^2-5;
return f;
}
Run Code Online (Sandbox Code Playgroud)
问题:我对这部分代码有以下错误:
我的目标:我正在编写一个代码,以便在C++,Visual Studio 2012中找到以下多项式的根:

我不知道如何解决这个错误,因为我正在学习C++,这是我第一次遇到这个错误.上面只有两个错误; 我的其余代码没有错误.非常感谢您的帮助.谢谢!
c++ compiler-errors visual-studio operands visual-studio-2012
我的程序:包含5个文本框,如下图所示:

我的目标:我想在冒号":"之后解析settings.txt文件中的任何内容.所以,例如:我想要(459800090581).在阅读"第一手册:(459800090581)"后显示在我的第一个文本框中.来自Settings.txt文件的行.这适用于其他各个领域.
我试图谷歌如何解析文本文件,但我无法找到一个简单的文件解析程序,这将帮助我学习和理解如何在C#中进行文件解析.该计划将帮助我快速,轻松地学习这项技术,非常感谢您的帮助!谢谢!!:)