有史以来第一次,我正在研究RichTextBoxC#Windows窗体中的控件.我知道我的应用程序中需要这个控件,因为TextBox它太简单了.
我有以下代码:
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 _19_richtextbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void richTextBoxHome_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == (char)(Keys.Return))
{
richTextBoxChat.AppendText("Home:" + richTextBoxHome.Text + "\n");
richTextBoxHome.Clear();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
目前我只想要在一个中输入的任何内容在击中时RichTextBox显示在另一个RichTextBox上Return.
问题是,每次我点击时Return,数据都被转移到另一个控件,但第一个控件在光标前留下了回车符.每次我击中都会发生这种情况Return.两个控件都接受多行输入.我如何让它停止这样做?
我想用一种方法将"Home:"部分用粗体表示.
我在搜索中发现的信息非常少.以下是我能理解的唯一实际代码.
rtb1.Rtf = @"{\rtf1\ansi {\b hello} {\i World}}" …Run Code Online (Sandbox Code Playgroud) 有人可以告诉我@键的标识符吗?
例如keys.Escape用于ESC键.我想知道它是什么@
谢谢.
我有一个C#应用程序,它由3种形式组成:
Run Code Online (Sandbox Code Playgroud)1: Battleship Game GUI 2: Network GUI (does client/server connections) 3: Chat GUI
首先加载表单1.当用户选择时setup network,显示表单2.
当用户选择发送聊天或收到聊天时,将显示聊天.
我希望表单2处理所有消息并将相关消息传递给相关GUI以进一步解码消息.
我还处于发展的早期阶段.目前我正在尝试使用代表在表单之间进行通信.
这是最好的方法吗?关于应用程序组件相互发送消息的最佳实践是什么?
我想知道是否有办法通过使用getElementById访问图像的onclick属性?
例如
lastTopic = document.getElementById('topicID').src;
lastTitle = document.getElementById('topicID').title;
Run Code Online (Sandbox Code Playgroud)
这些变量存储,所以我想知道是否有办法访问相关的onclick事件呢?
谢谢.
我有以下有关异步套接字编程的代码:
public void ServerBeginAceept(ushort ServerPort)
{
try
{
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, ServerPort);
ServerSocket.Bind(ipEndPoint);
ServerSocket.Listen(MAX_CONNECTIONS);
IAsyncResult result = ServerSocket.BeginAccept(new AsyncCallback(ServerEndAccept), ServerSocket);
}
}
public void ServerEndAccept(IAsyncResult iar)
{
try
{
ServerSocket = (Socket)iar.AsyncState;
CommSocket = ServerSocket.EndAccept(iar);
}
}
public void ClientBeginConnect(string ServerIP, ushort ServerPort)
{
try
{
CommSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(ServerIP), ServerPort);
IAsyncResult result = CommSocket.BeginConnect(ipEndPoint, new AsyncCallback(ClientEndConnect), CommSocket);
}
}
public void ClientEndConnect(IAsyncResult iar)
{ …Run Code Online (Sandbox Code Playgroud) 我需要一些socket.listen的帮助.
我的max_connections设置为1.但即使在客户端连接后如果另一个客户端尝试连接,在客户端它也说它已连接,尽管服务器没有报告任何新内容.
我的应用程序在一个服务器和一个客户端之间 如果任何其他客户端尝试连接,而已经有连接,我希望连接被拒绝.
请帮助一些想法.
非常感谢你.
我有以下课程:
public class NewGameContract {
public boolean HomeNewGame = false;
public boolean AwayNewGame = false;
public boolean GameContract(){
if (HomeNewGame && AwayNewGame){
return true;
} else {
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用它时:
if (networkConnection){
connect4GameModel.newGameContract.HomeNewGame = true;
boolean status = connect4GameModel.newGameContract.GameContract();
switch (status){
case true:
break;
case false:
break;
}
return;
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
incompatible types found: boolean required: int on the following
`switch (status)` code.
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?