‘壹’ C#的webbrowser控件如何实现类似手机的拖动效果
需要自定义webbrowser的mousedown和mouseup事件,然后根据位置控制滚动条的位置!
1.引用mshtml;
using mshtml;
2.定义全局变量:
private Point p=new Point(0,0); //用来记录上次鼠标按下时的坐标
3.在form_actived事件中定义事件:
webbrowser1.Document.MouseUp += new HtmlElementEventHandler(Document_MouseUp);
webbrowser1..Document.MouseDown += new HtmlElementEventHandler(Document_MouseDown);
4.定义webbroser的mousedown事件
private void Document_MouseDown(object sender, HtmlElementEventArgs e)
{
p = e.ClientMousePosition; //记录下鼠标按下时的位置并赋值给p
}
5.定义webbroser的mouseup事件
private void Document_MouseUp(object sender, HtmlElementEventArgs e)
{
IHTMLDocument2 document = (IHTMLDocument2)WB1.Document.DomDocument;
document.parentWindow.scrollBy(e.ClientMousePosition.X - p.X, e.ClientMousePosition.Y - p.Y); //要滚动的位置
}
‘贰’ C# 自定义web控件编写
参考一下:在页面引用就可以 这只是简单的自定义控件
namespace MyServerControl
{
[DefaultProperty("Text")]//(打开属性时)默认选择的属性
[ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]//自定义服务器控件在页面上面显示的标记
public class ServerControl1 : WebControl
{
[Bindable(true)]//是否通常绑定
[Category("外观")]
[DefaultValue("")]
[Description("显示的文本")]//属性的描述
[Localizable(true)]
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? "[" + this.ID + "]" : s);
}
set
{
ViewState["Text"] = value;
}
}
private string imageurl;
[Description("要显示图片的路径")]//属性的描述
[Category("样式")]
[EditorAttribute(typeof(ImageUrlEditor), typeof(UITypeEditor))]//让属性里面有选择图片的按钮”...“
public string Imageurl
{
get { return imageurl; }
set { imageurl = value; }
}
[Bindable(true)]//是否通常绑定
[Category("字体")]
[DefaultValue("")]
[Description("设置文本框的字体的大小单位为px")]//属性的描述
[Localizable(true)]
public string Fontsize
{
get {
String font = (String)ViewState["Fontsize"];
return ((font == null) ? "14px" : font+"px");
}
set { ViewState["Fontsize"] = value; }
}
protected override void Render(HtmlTextWriter Write)
{
string path="";
if(imageurl!=null)
{
path = this.ResolveClientUrl(Imageurl);//取图片路径对应的在客户端的路径
}
WebColorConverter wcolor = new WebColorConverter();//进行颜色转换为RGB格式//在RGB和color间切换的对象
Write.Write("<input type=\"text\" id=\"" + this.ID + "\" name=\"" + this.ID + "\" style=\"background-color:" + wcolor.ConvertToString(base.BackColor) + " ;background-image:url(" + path + "); font-size:" + Fontsize + "\" value=\"");
Write.Write(Text);
Write.Write("\"/>");
}
}
}
‘叁’ 请教vc中用cwebBrowser2控件实现网页模拟点击的问题
如果只是要实现点击下按钮的话应该可以
你可以遍历所有控件,然后判断是INPUT,判断是BUTTON类型,然后判断ID(通过网站源代码看)是不是这个按钮的,然后就check()就可以了。
C/C++ code
MSHTML::IHTMLElementCollection *objAllElement=NULL;
MSHTML::IHTMLDocument2 *objDocument=NULL;
CString strUrl,strTemp;
strUrl=m_ctrlWeb.GetLocationURL();//得到当前网页的URL
if(strUrl.IsEmpty())
return;
objDocument=(MSHTML::IHTMLDocument2 *)m_ctrlWeb.GetDocument(); //由控件得到IHTMLDocument2接口指针
objDocument->get_all(&objAllElement); //得到网页所有元素的集合
//由于所有页面下载完后都会执行这个函数,所以必须根据URL判断消息来源网页
‘肆’ 如何通过javascript操作web控件的自定义属性
举个例子吧,比如操作TextBox控件,TextBox控件中没有IsNotNull属性,但是可以自己添加一个IsNotNull属性,从而作为一个标记来方便编写程序。
虽然IDE会提示“IsNotNull不是TextBox的属性”这个警告信息但是也不妨碍使用!
代码:
<asp:TextBox ID="TextBox1" runat="server"
IsNotNull="e"></asp:TextBox>
编写Javascript代码:
<script language=javascript
type="text/javascript">
function getClick()
{
var
c=document.getElementById("<%=TextBox1.ClientID %>");
if(c.IsNotNull == 1)
{
alert("IsNotNull is 1");
}
else if(c.IsNotNull == 0)
{
alert("IsNotNull is
0");
}
else
{
alert(c.IsNotNull);
//不是0或者1时会显示IsNotNull的属性值
}
}
</script>
‘伍’ 如何在C#中根据已有的控件(比如TextBox),派生出一个自定义控件最好附上例子,新手。。。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;
using System.Collections;
namespace FumaCRM_BS.WebControls
{
/// <summary>
/// 普通文本框封装
/// </summary>
[ToolboxData("<{0}:FBSTextBox runat=server></{0}:FBSTextBox>"), DefaultProperty("ValidType")]
public class FBSTextBox : System.Web.UI.WebControls.TextBox, INamingContainer
{
/// <summary>
/// 构造函数,初始化部分属性
/// </summary>
public FBSTextBox()
{
clearText = false;
decimalDigits = 2;
gotfocusColor = Color.FromArgb(255, 255, 192);
jsSrc = "../Resource/Js/checkvalid.js";
}
#region Fields
private string errorMessage;
private string validRegularExpression;
private AvailableType validType;
private bool clearText;
private Color gotfocusColor;
private Color lostfocusColor;
private RestrictType restType;
private int decimalDigits;
private string jsSrc;
private string buttonId;
#endregion
#region Properties
[Category("Appearance"), Browsable(true), Description("错误信息")]
public string ErrorMessage
{
get
{
return errorMessage;
}
set
{
errorMessage = value;
}
}
[Category("Appearance"), Browsable(true), Description("自定义正则表达式")]
public string ValidRegularExpression
{
get
{
return validRegularExpression;
}
set
{
validRegularExpression = value;
}
}
[Category("Appearance"), Browsable(true), Description("验证类型")]
public AvailableType ValidType
{
get
{
return validType;
}
set
{
validType = value;
}
}
[Category("Appearance"), Browsable(true), Description("是否清空错误的数据")]
public bool ClearText
{
get
{
return clearText;
}
set
{
clearText = value;
}
}
[Category("Appearance"), DefaultValue("White"), Bindable(true), Description("获得焦点时的颜色")]
public Color GotfocusColor
{
get
{
return gotfocusColor;
}
set
{
gotfocusColor = value;
}
}
[Category("Appearance"), DefaultValue("White"), Bindable(true), Description("失去焦点时的颜色")]
public Color LostfocusColor
{
get
{
return lostfocusColor;
}
set
{
lostfocusColor = value;
}
}
[Category("Appearance"), Browsable(true), Description("限制输入类型")]
public RestrictType RestType
{
get
{
return restType;
}
set
{
restType = value;
}
}
[Category("Appearance"), DefaultValue("2"), Bindable(false), Description("限制输入浮点数小数位数")]
public int DecimalDigits
{
get
{
return decimalDigits;
}
set
{
decimalDigits = value;
}
}
[Category("Appearance"), Bindable(false), Description("JS脚本相对路径")]
public string JsSrc
{
get
{
return jsSrc;
}
set
{
jsSrc = value;
}
}
[Category("Appearance"), Bindable(false), Description("回车触发Click事件的ButtonID")]
public string ButtonID
{
get
{
return buttonId;
}
set
{
buttonId = value;
}
}
#endregion
#region CreateControl
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ClientScriptManager client = Page.ClientScript;
#region 注册js脚本
if (!client.IsClientScriptBlockRegistered("checkvalid"))
{
if (jsSrc == null || jsSrc == "")
jsSrc = "../Resource/Js/checkvalid.js";
client.RegisterStartupScript(this.GetType(), "checkvalid", "<script language=\"javascript\" src=\"" + jsSrc + "\"></script>");
}
#endregion
#region 获得/失去焦点改变背景颜色
base.Attributes.Add("onBlur", "changeColor('" + ClientID + "', '" + Color2WebColorString(lostfocusColor) + "');");
base.Attributes.Add("onfocus", "changeColor('" + ClientID + "', '" + Color2WebColorString(gotfocusColor) + "');");
if (buttonId != null && buttonId != string.Empty)
{
base.Attributes.Add("onkeydown", "keydown('" + buttonId + "');");
}
else
{
base.Attributes.Add("onkeydown", "nokeydown();");
}
#endregion
if (ValidType != AvailableType.NoSet)
{
string regExp = GetRegularExpressions(ValidType);
base.Attributes.Add("onBlur", "isValid('" + ClientID + "','" + regExp + "','" + Color2WebColorString(lostfocusColor) + "','" + errorMessage + "','" + clearText + "');");
}
if (validRegularExpression != null && validRegularExpression.Trim() != string.Empty)
{
string regExp = validRegularExpression;
base.Attributes.Add("onBlur", "isValid('" + ClientID + "','" + regExp + "','" + Color2WebColorString(lostfocusColor) + "','" + errorMessage + "','" + clearText + "');");
}
if (RestType != RestrictType.NoSet)
{
string regExp = GetRegularExpressions(RestType);
base.Attributes.Add("onkeyup", "restrictedInput('" + ClientID + "','" + regExp + "');");
}
}
#endregion
#region Enums
/// <summary>
/// 校验类型
/// </summary>
public enum AvailableType
{
NoSet = 0,
Int = 1,
PositiveInt = 2,
NegativeInt = 3,
NonNegativeInt = 4,
NonPositiveInt = 5,
RegularExpression = 6,
Float = 7,
PositiveFloat = 8,
NegativeFloat = 9,
NonNegativeFloat = 10,
NonPositiveFloat = 11,
Email = 12,
Url = 13,
Money = 14
}
/// <summary>
/// 限制输入类型
/// </summary>
public enum RestrictType
{
NoSet = 0,
Letter = 1,
SmallLetter = 2,
CapitalLetter = 3,
Int = 4,
Float = 5,
}
#endregion
#region Private Functions
private string GetRegularExpressions(RestrictType restType)
{
switch (restType)
{
case RestrictType.Letter:
return @"^[A-Za-z]+$";
case RestrictType.CapitalLetter:
return @"^[A-Z]+$";
case RestrictType.SmallLetter:
return @"^[a-z]+$";
case RestrictType.Int:
return @"^[0-9]*[0-9][0-9]*$";
case RestrictType.Float:
if (decimalDigits == 0)
return @"^\d*\.?\d{0,}$";
else
return @"^\d*\.?\d{0," + decimalDigits + "}$";
default:
return "";
}
}
private string GetRegularExpressions(AvailableType avilType)
{
switch (avilType)
{
case AvailableType.Int://整数
return @"^-?\\d+$";
case AvailableType.PositiveInt://正整数
return @"^[0-9]*[1-9][0-9]*$";
case AvailableType.NegativeInt://负整数
return @"^-[0-9]*[1-9][0-9]*$";
case AvailableType.NonNegativeInt://非负整数
return @"^\\d+$";
case AvailableType.NonPositiveInt://非正整数
return @"^((-\\d+)|(0+))$";
case AvailableType.Float://浮点数
return @"^(-?\\d+)(\\.\\d+)?$";
case AvailableType.PositiveFloat://正浮点
return @"^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$";
case AvailableType.NegativeFloat://负浮点
return @"^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$";
case AvailableType.NonNegativeFloat://非正浮点
return @"^\\d+(\\.\\d+)?$";
case AvailableType.NonPositiveFloat://非负浮点
return @"^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$";
case AvailableType.Email://E-mail
return @"^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
case AvailableType.Url://Url
return @"^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$";
case AvailableType.Money://Money
return @"^(\\d+|[1-9])(\\.\\d{0,2})?$";
default:
return "";
}
}
/// <summary>
/// 颜色转换函数
/// </summary>
/// <param name="c"></param>
/// <returns></returns>
private string Color2WebColorString(Color c)
{
WebColorConverter wcc = new WebColorConverter();
return wcc.ConvertToString(c);
}
#endregion
}
}
‘陆’ 怎么用C#来写一个Web的自定义控件
推介您用烈日传奇辅助免费版功能比如有:强力移动,幻影攻击,过攻击超速,瞬间野蛮,自动解包,道士挂机打怪,自动寻路,快捷键购买物品,自动烈火,楼主可以去看看,这应该就是您所需要的吧!
‘柒’ C#编写用户自定义控件时,引用web的webservice,提示错误
需要在初始化客户端时指定终结点(endpoint)的配置名:
WeatherService.WeatherWSSoapClientclient=
newWeatherService.WeatherWSSoapClient("WeatherWSSoap");
‘捌’ C# web页面 浮动控件如何做
放到DIV里面,然后设置DIV的style="position:fixed;top:0px;left:0px"是放在左上
style="position:fixed;bottom:0px;right:0px"是放在右下
‘玖’ 求助!!!我在vs2010 c#中添加一个webbrowser控件,在控件中初始化一页面,然后输入
WebBrowserweb=newWebBrowser();
//webBrowser1.Navigate(url);
//web.Url=newUri(url);
web.Navigate(url);
//等待网页加载
while(web.ReadyState<WebBrowserReadyState.Complete)Application.DoEvents();
HtmlDocumenthtmldoc=web.Document;//已经获取到html
//下面自己解析
for(inti=1;i<=10;i++)
{
HtmlElementhtml=htmldoc.GetElementById(i.ToString());
HtmlElementCollectionc=html.GetElementsByTagName("a");
stringa=c[0].GetAttribute("href");
strings=c[0].InnerText;
//MessageBox.Show(c[0].InnerHtml+s);
UrlAnText.Add(a,s);
}