使用while循环而不是游标是个好主意吗?游标有哪些优点/缺点?
首先,我在http://swigartconsulting.blogs.com/tech_blender/2005/08/how_to_move_the.html找到了此代码:
public class Win32
{
[DllImport("User32.Dll")]
public static extern long SetCursorPos(int x, int y);
[DllImport("User32.Dll")]
public static extern bool ClientToScreen(IntPtr hWnd, ref POINT point);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
}
}
Run Code Online (Sandbox Code Playgroud)
将以下代码粘贴到按钮的click eventhandler中:
Win32.POINT p = new Win32.POINT();
p.x = button1.Left + (button1.Width / 2);
p.y = button1.Top + (button1.Height / 2);
Win32.ClientToScreen(this.Handle, ref p);
Win32.SetCursorPos(p.x, p.y);
Run Code Online (Sandbox Code Playgroud)
这会将鼠标指针移动到按钮的中心.
这段代码效果很好,但我似乎无法弄清楚如何扩展它.假设我有一个Internet浏览器(嵌入在windows窗体中)打开一个网页(一些我手头不知道的随机页面),里面有一个下拉列表框.我已修改上面的代码,将光标移动到下拉列表框(使用下面显示的鼠标单击方法将列表向下拖放),并在列表中上下移动,突出显示每个项目作为鼠标指针过去,但对于我的生活,我无法弄清楚如何实际让鼠标点击当前选定的项目来保持选择.我正在这样做的方式现在下拉列表框只是关闭,选择不会改变.我正在使用以下代码进行鼠标单击(这会使列表下拉):
private static void MouseClick(int x, int y, IntPtr handle) //handle for the browser …Run Code Online (Sandbox Code Playgroud) 如何将光标图标更改为桌面上常见的"忙碌图标"?如何设置动画文件(.gif,.ani)而不是光标?
我是一个编程新手,我在互联网上找到了这段代码,它工作正常
Cursor c=db.query(DataBase.TB_NAME, new String[] {DataBase.KEY_ROWID,DataBase.KEY_RATE}, DataBase.KEY_ROWID+"= 1", null, null, null, null);
if(c!=null)
{
c.moveToFirst();
}
Run Code Online (Sandbox Code Playgroud)
但我无法理解使用的
if(c!=null)
{
c.moveToFirst();
}
Run Code Online (Sandbox Code Playgroud)
部分.它究竟做了什么,如果我删除了
if(c!=null) { c.moveToFirst(); }
Run Code Online (Sandbox Code Playgroud)
部分,代码不起作用.
我在Android应用程序的sqlite数据库中存储了大量二进制数据(protobufs),却没有意识到Android Cursor只能容纳最多1MB的数据.我现在知道我应该将这些二进制blob存储在文件中,并且只引用sqlite数据库条目中的文件.
我需要升级数据库(应用程序已经使用了一段时间)才能将这些二进制块移动到文件中.问题是某些用户的数据可能已经超过了1MB的限制,我无法从数据库中检索它(访问Cursor包含大blob的单行的结果IllegalStateException: Couldn't read row 0, col 0 from CursorWindow. Make sure the Cursor is initialize before accessing data from it).
如何检索Cursor已存储在sqlite数据库中的大于1MB 限制的二进制blob ?
我需要一个代码来查找文本框/文本区域中光标的当前位置.它应该适用于chrome和firefox.以下是我使用的代码:
<!DOCTYPE html>
<html>
<head>
<script>
function textbox()
{
document.getElementById('Javascript_example').value = document.activeElement.id;
var ctl = document.getElementById('Javascript_example');
alert(ctl);
var startPos = ctl.selectionStart;
alert(startPos);
var endPos = ctl.selectionEnd;
alert(endPos);
}
</script>
</head>
<body>
<input id="Javascript_example" name="one" type="text" value="Javascript_example" onclick="textbox()">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
在我的网站中,我使用svg元素.有时我需要它们是可点击的,因此我希望指针光标在它们上面.
但是添加css类或样式
cursor: pointer;
Run Code Online (Sandbox Code Playgroud)
不行.
这是示例元素
<object id="male2" type="image/svg+xml" data="course/ani/male2.svg" style="left: 87px; bottom: 56px;" es-character="male2"></object>
Run Code Online (Sandbox Code Playgroud)
似乎它与svg无法合作.任何人都知道如何解决,或如何解决它?
我从互联网下载数据库.我将它保存在我的datases文件夹中,然后打开它.在数据库内部有一个包含6个字段的"广告"表.其中2个字段是BLOB.当我想从这个表中读取...我有一些问题...我注意到当我读取一个blob字段大于1兆字节的行时,这会导致异常..."从行获取字段槽0 col 0失败".如果它有点blob,一切都还可以......在此先感谢:)
1 Cursor cursor = contentResolver.query(MY_URI, new String[] { "first" }, null, null, null);
2 if (cursor != null) {
3 if (cursor.moveToFirst()) {
4 first = cursor.getString(cursor.getColumnIndex("first"));
5 cursor.close();
6 }
7 }
Run Code Online (Sandbox Code Playgroud)
然后在第3行(根据日志),我偶尔会遇到这个例外(摘录如下):
android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
at android.database.CursorWindow.<init>(CursorWindow.java:134)
at android.database.CursorWindow.<init>(CursorWindow.java:41)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:709)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:707)
at android.database.CursorWindow.newFromParcel(CursorWindow.java:718)
at android.database.BulkCursorProxy.getWindow(BulkCursorNative.java:196)
Run Code Online (Sandbox Code Playgroud)
...
任何想法为什么抛出这个例外?谢谢!