stringstr=textboxtexttostring();
string[]strArr=strSplit(newchar[]{''});
strArr里每一个再用一个string转int的函数就可以了
Private Sub Command1_Click()
meshow
Dim x As Long, sum As Long, n As Long
n = Val(InputBox("输入N值"))
For i = 1 To n
x = 1
For j = 1 To i
x = x j
Next
sum = sum + x
Next
print sum
End Sub
一楼好搞笑 “你给的式子去掉感叹号就是了”
窗口程序获得键盘输入的值,你肯定得拖个textbox之类的文本框吧,然后在后台定义变量(双击你拖到面板上的文本框,进去后台),用变量来获得你输入的值呀,比如
int
i=
ConvertToInt32(textboxtext);//ConvertToInt32是把你从键盘获得的值(字符)转换成整型,textboxtext是获取文本框的值,当然这个得看你的文本框的name属性是什么(第一个默认是textbox1,第二个默认是textbox2,以此类推),一般规范编程都要改名字的额,比我成UID(用户名),那么我获取就是UIDtext
1、父页面
代码如下:
<input type="text" id="name" value="zhangsan"/>
<a href="ahtml" target="_blank">预览</a>
2、子页面,也就是ahtml获取父页面中文本框的value
代码如下:
$(function(){
consoleinfo(windowopenerdocumentgetElementById("name")value);
});
这样控制台中出来的则是父页面文本框的值
全局键盘钩子,如下,你再把键盘钩子的数据弄到textbox就可以了。
using System;
using SystemRuntimeInteropServices;
using SystemReflection;
using SystemThreading;
using SystemWindowsForms;
using SystemDiagnostics;
using SystemCollectionsGeneric;
namespace HookGlobal
{
/// <summary>
/// 这个类可以让你得到一个在运行中程序的所有键盘事件
/// 并且引发一个带KeyEventArgs和MouseEventArgs参数的NET事件以便你很容易使用这些信息
/// </summary>
/// <remarks>
/// 修改:lihx
/// 修改时间:04118
/// </remarks>
public class KeyBordHook
{
private const int WM_KEYDOWN = 0x100;
private const int WM_KEYUP = 0x101;
private const int WM_SYSKEYDOWN = 0x104;
private const int WM_SYSKEYUP = 0x105;
//全局的事件
public event KeyEventHandler OnKeyDownEvent;
public event KeyEventHandler OnKeyUpEvent;
public event KeyPressEventHandler OnKeyPressEvent;
static int hKeyboardHook = 0; //键盘钩子句柄
//鼠标常量
public const int WH_KEYBOARD_LL = 13; //keyboard hook constant
HookProc KeyboardHookProcedure; //声明键盘钩子事件类型
//声明键盘钩子的封送结构类型
[StructLayout(LayoutKindSequential)]
public class KeyboardHookStruct
{
public int vkCode; //表示一个在1到254间的虚似键盘码
public int scanCode; //表示硬件扫描码
public int flags;
public int time;
public int dwExtraInfo;
}
//装置钩子的函数
[DllImport("user32dll", CharSet = CharSetAuto, CallingConvention = CallingConventionStdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
//卸下钩子的函数
[DllImport("user32dll", CharSet = CharSetAuto, CallingConvention = CallingConventionStdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
//下一个钩挂的函数
[DllImport("user32dll", CharSet = CharSetAuto, CallingConvention = CallingConventionStdCall)]
public static extern int CallNextHookEx(int idHook, int nCode, Int32 wParam, IntPtr lParam);
[DllImport("user32")]
public static extern int ToAscii(int uVirtKey, int uScanCode, byte[] lpbKeyState, byte[] lpwTransKey, int fuState);
[DllImport("user32")]
public static extern int GetKeyboardState(byte[] pbKeyState);
[DllImport("kernel32dll", CharSet = CharSetAuto,
CallingConvention = CallingConventionStdCall)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam);
//先前按下的键
public List<Keys> preKeys = new List<Keys>();
/// <summary>
/// 墨认的构造函数构造当前类的实例并自动的运行起来
/// </summary>
public KeyBordHook()
{
Start();
}
//析构函数
~KeyBordHook()
{
Stop();
}
public void Start()
{
//安装键盘钩子
if (hKeyboardHook == 0)
{
KeyboardHookProcedure = new HookProc(KeyboardHookProc);
//hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, MarshalGetHINSTANCE(AssemblyGetExecutingAssembly()GetModules()[0]), 0);
Process curProcess = ProcessGetCurrentProcess();
ProcessModule curModule = curProcessMainModule;
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, GetModuleHandle(curModuleModuleName), 0);
if (hKeyboardHook == 0)
{
Stop();
throw new Exception("SetWindowsHookEx ist failed");
}
}
}
public void Stop()
{
bool retKeyboard = true;
if (hKeyboardHook != 0)
{
retKeyboard = UnhookWindowsHookEx(hKeyboardHook);
hKeyboardHook = 0;
}
//如果卸下钩子失败
if (!(retKeyboard)) throw new Exception("UnhookWindowsHookEx failed");
}
private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
{
if ((nCode >= 0) && (OnKeyDownEvent != null || OnKeyUpEvent != null || OnKeyPressEvent != null))
{
KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)MarshalPtrToStructure(lParam, typeof(KeyboardHookStruct));
//当有OnKeyDownEvent 或 OnKeyPressEvent不为null时,ctrl alt shift keyup时 preKeys
//中的对应的键增加
if ((OnKeyDownEvent != null || OnKeyPressEvent != null) && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
{
Keys keyData = (Keys)MyKeyboardHookStructvkCode;
if (IsCtrlAltShiftKeys(keyData) && preKeysIndexOf(keyData) == -1)
{
preKeysAdd(keyData);
}
}
//引发OnKeyDownEvent
if (OnKeyDownEvent != null && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
{
Keys keyData = (Keys)MyKeyboardHookStructvkCode;
KeyEventArgs e = new KeyEventArgs(GetDownKeys(keyData));
OnKeyDownEvent(this, e);
}
//引发OnKeyPressEvent
if (OnKeyPressEvent != null && wParam == WM_KEYDOWN)
{
byte[] keyState = new byte[256];
GetKeyboardState(keyState);
byte[] inBuffer = new byte[2];
if (ToAscii(MyKeyboardHookStructvkCode,
MyKeyboardHookStructscanCode,
keyState,
inBuffer,
MyKeyboardHookStructflags) == 1)
{
KeyPressEventArgs e = new KeyPressEventArgs((char)inBuffer[0]);
OnKeyPressEvent(this, e);
}
}
//当有OnKeyDownEvent 或 OnKeyPressEvent不为null时,ctrl alt shift keyup时 preKeys
//中的对应的键删除
if ((OnKeyDownEvent != null || OnKeyPressEvent != null) && (wParam == WM_KEYUP || wParam == WM_SYSKEYUP))
{
Keys keyData = (Keys)MyKeyboardHookStructvkCode;
if (IsCtrlAltShiftKeys(keyData))
{
for (int i = preKeysCount - 1; i >= 0; i--)
{
if (preKeys[i] == keyData)
{
preKeysRemoveAt(i);
}
}
}
}
//引发OnKeyUpEvent
if (OnKeyUpEvent != null && (wParam == WM_KEYUP || wParam == WM_SYSKEYUP))
{
Keys keyData = (Keys)MyKeyboardHookStructvkCode;
KeyEventArgs e = new KeyEventArgs(GetDownKeys(keyData));
OnKeyUpEvent(this, e);
}
}
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
private Keys GetDownKeys(Keys key)
{
Keys rtnKey = KeysNone;
foreach (Keys keyTemp in preKeys)
{
switch (keyTemp)
{
case KeysLControlKey:
case KeysRControlKey:
rtnKey = rtnKey | KeysControl;
break;
case KeysLMenu:
case KeysRMenu:
rtnKey = rtnKey | KeysAlt;
break;
case KeysLShiftKey:
case KeysRShiftKey:
rtnKey = rtnKey | KeysShift;
break;
default:
break;
}
}
rtnKey = rtnKey | key;
return rtnKey;
}
private Boolean IsCtrlAltShiftKeys(Keys key)
{
switch (key)
{
case KeysLControlKey:
case KeysRControlKey:
case KeysLMenu:
case KeysRMenu:
case KeysLShiftKey:
case KeysRShiftKey:
return true;
default:
return false;
}
}
}
}
以上就是关于C#如何获取窗体的TextBox的值全部的内容,包括:C#如何获取窗体的TextBox的值、用VB编写程序,求S=1!+2!+3!+4!+5!+6!+7!+8!,并在窗体中输入S的值、c#窗口程序中怎么输入数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)