『壹』 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);
}