MYVB-Notepad

shdocvw

프로그래밍/C#2014. 5. 31. 12:37

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SHDocVw;
using mshtml;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            InternetExplorer ie = new InternetExplorer();
            IWebBrowserApp webBrowser = (IWebBrowserApp)ie;
            // 브라우져 크기 지정
            webBrowser.Height = 700;
            webBrowser.Width = 900;
            webBrowser.Visible = true;

            webBrowser.Navigate("http://www.google.com");

            Thread.Sleep(3000);

            IHTMLDocument2 doc2 = (IHTMLDocument2)webBrowser.Document;
            IHTMLDocument3 doc3 = (IHTMLDocument3)webBrowser.Document;

            // Document 속성 읽기
            string title = doc2.title;
            string url = doc2.url;
            textBox1.Text = url;

            // 특정 Element 컨트롤
            IHTMLElement q = doc3.getElementsByName("q").item("q", 0);
            q.setAttribute("value", "microsoft");

            IHTMLFormElement form = doc2.forms.item(Type.Missing, 0);
            form.submit();

        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            try
            {
                // 특정 URL을 갖는 IE 찾기
                SHDocVw.WebBrowser wb = FindIE("https://www.google.co.kr/");

                // URL을 다른 것으로 변경
                if (wb != null)
                    wb.Navigate("www.bing.com");
            }
            catch (System.Exception)
            {

                throw;
            }


        }
        static SHDocVw.WebBrowser FindIE(string url)
        {
            Uri uri = new Uri(url);
            var shellWindows = new SHDocVw.ShellWindows();
            foreach (SHDocVw.WebBrowser wb in shellWindows)
            {
                Uri wbUri = new Uri(wb.LocationURL);
                if (wbUri.Equals(uri))
                {
                    return wb;
                }
            }
            return null;
        }

    }

}

 

Dim str() As String = GetCommandLineArgs()   '명령행인수를 변수로 돌려받는다.

System.Environment.GetCommandLineArgs

C:\1.xml 로 저장한 티스토리 백업파일에서 Title가져오기..

<blog>

<post>

<title>제목 </title>

</post>

</blog>



using System;

using System.Xml;

using System.Xml.Linq;


namespace tet

{

class Program

{

public static void Main(string[] args)

{

using (XmlReader reader = XmlReader.Create("c:\\1.xml"))

{

   while (reader.Read())

   {

// Only detect start elements.

if (reader.IsStartElement())

{

   // Get element name and switch on it.

   switch (reader.Name)

   {

case "title":

   // Detect this article element.

   Console.WriteLine("Start <article> element.");

   // Search for the attribute name on this current node.

   string attribute1 = reader["title"];

   if (attribute1 != null)

   {

Console.WriteLine("  Has attribute name: " + attribute1);

   }

   // Next read will contain text.

   if (reader.Read())

   {

Console.WriteLine("  Text node: " + reader.Value.Trim());

   }

   break;

   }

}

   }

}


Console.Write("Press any key to continue . . . ");

Console.ReadKey(true);

}

}

}



using System;
using CookComputing.XmlRpc;
using System.Net;
using System.IO;

namespace MetaWeblogTester
{
    [XmlRpcMissingMapping(MappingAction.Ignore)]
    public struct Enclosure
    {
        public int length;
        public string type;
        public string url;
    }

    [XmlRpcMissingMapping(MappingAction.Ignore)]
    public struct Source
    {
        public string name;
        public string url;
    }

    [XmlRpcMissingMapping(MappingAction.Ignore)]
    public struct UserBlog
    {
        public string url;
        public string blogid;
        public string blogName;
    }

    [XmlRpcMissingMapping(MappingAction.Ignore)]
    public struct UserInfo
    {
        public string url;
        public string blogid;
        public string blogName;
        public string firstname;
        public string lastname;
        public string email;
        public string nickname;
    }


    [XmlRpcMissingMapping(MappingAction.Ignore)]
    public struct Post
    {
        [XmlRpcMissingMapping(MappingAction.Error)]
        [XmlRpcMember(Description = "Required when posting.")]
        public DateTime dateCreated;
        [XmlRpcMissingMapping(MappingAction.Error)]
        [XmlRpcMember(Description = "Required when posting.")]
        public string description;
        [XmlRpcMissingMapping(MappingAction.Error)]
        [XmlRpcMember(Description = "Required when posting.")]
        public string title;

        public string[] categories;
        public Enclosure enclosure;
        public string link;
        public string permalink;
        [XmlRpcMember(
           Description = "Not required when posting. Depending on server may "
           + "be either string or integer. "
           + "Use Convert.ToInt32(postid) to treat as integer or "
           + "Convert.ToString(postid) to treat as string")]
        public object postid;
        public Source source;
        public string userid;

        public object mt_allow_comments;
        public object mt_allow_pings;
        public object mt_convert_breaks;
        public string mt_text_more;
        public string mt_excerpt;
    }

    public struct Category
    {
        public string description;
        public string title;
    }

    public struct CategoryInfo
    {
        public string description;
        public string htmlUrl;
        public string rssUrl;
        public string title;
        public string categoryid;
    }

    [XmlRpcMissingMapping(MappingAction.Ignore)]
    public struct MediaObjectUrl
    {
        public string url;
    }

    [XmlRpcMissingMapping(MappingAction.Ignore)]
    public struct MediaObject
    {
        public string name;
        public string type;
        public byte[] bits;
    }

    public class MetaWeblog : XmlRpcClientProtocol
    {
        public MetaWeblog(String uri)
        {
            base.Url = uri;
        }
        [XmlRpcMethod("metaWeblog.getRecentPosts")]
        public Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts)
        {
            return (Post[])this.Invoke("getRecentPosts", new object[] { blogid, username, password, numberOfPosts });
        }
        [XmlRpcMethod("metaWeblog.newPost")]
        public string newPost(string blogid, string username, string password, Post content, bool publish)
        {
            return (string)this.Invoke("newPost", new object[] { blogid, username, password, content, publish });
        }
        [XmlRpcMethod("metaWeblog.editPost")]
        public bool editPost(string postid, string username, string password, Post content, bool publish)
        {
            return (bool)this.Invoke("editPost", new object[] { postid, username, password, content, publish });
        }
        [XmlRpcMethod("blogger.deletePost")]
        public bool deletePost(string appKey, string postid, string username, string password, bool publish)
        {
            return (bool)this.Invoke("deletePost", new object[] { appKey, postid, username, password, publish });
        }
        [XmlRpcMethod("blogger.getUsersBlogs")]
        public UserBlog[] getUsersBlogs(string appKey, string username, string password)
        {
            return (UserBlog[])this.Invoke("getUsersBlogs", new object[] { appKey, username, password });
        }
        [XmlRpcMethod("blogger.getUserInfo")]
        public UserInfo getUserInfo(string appKey, string username, string password)
        {
            return (UserInfo)this.Invoke("getUserInfo", new object[] { appKey, username, password });
        }
        [XmlRpcMethod("metaWeblog.getPost")]
        public Post getPost(string postid, string username, string password)
        {
            return (Post)this.Invoke("getPost", new object[] { postid, username, password });
        }
        [XmlRpcMethod("metaWeblog.getCategories")]
        public Category[] getCategories(string blogid, string username, string password)
        {
            return (Category[])this.Invoke("getCategories", new object[] { blogid, username, password });
        }
        [XmlRpcMethod("metaWeblog.newMediaObject", Description = "Add a media object to a post using the " + "metaWeblog API. Returns media url as a string.")]
        public MediaObjectUrl newMediaObject(string blogid, string username, string password, MediaObject mediaObject)
        {
            return (MediaObjectUrl)this.Invoke("newMediaObject", new object[] { blogid, username, password, mediaObject });
        }
    }
}

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Net;

using System.IO;

using System.Text;

public class Module1
{


    private static CookieContainer cookie = new CookieContainer();
    public  string OpenURL(string URL, string Method = "GET", string PostData = null)
    {
        string functionReturnValue = null;

        HttpWebRequest request = null;

        request = (HttpWebRequest)WebRequest.Create(URL);

 


        var _with1 = request;

        _with1.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";

        _with1.ContentType = "application/x-www-form-urlencoded";

        _with1.Accept = "*/*";

        _with1.KeepAlive = true;

        _with1.ReadWriteTimeout = -1;

        _with1.Timeout = -1;

        _with1.Method = Method;
        // get,post등을 설정

        _with1.CookieContainer = cookie;


        if (Method == "POST")
        {
            TextWriter w = new StreamWriter(_with1.GetRequestStream());

            w.Write(PostData);

            w.Close();

            w = null;

        }


        HttpWebResponse Response = (HttpWebResponse)request.GetResponse();

        var _with2 = Response;


        if (_with2.StatusCode == HttpStatusCode.OK)
        {
            Stream receivestream = _with2.GetResponseStream();

            StreamReader readstream = null;

            readstream = new StreamReader(receivestream, System.Text.Encoding.UTF8);

            functionReturnValue = readstream.ReadToEnd();

            readstream.Close();

            _with2.Close();

        }
        return functionReturnValue;


    }

}

 

public static object httpdown(string url = "http://myvb.tistory.com/")

{

WebRequest wReq = WebRequest.Create(url);

WebResponse wResp = wReq.GetResponse();

System.IO.Stream RespStream = wResp.GetResponseStream();

System.IO.StreamReader Reader = new System.IO.StreamReader(RespStream, System.Text.Encoding.UTF8);

string RespHTML = Reader.ReadToEnd();

return RespHTML;

}

 

/**

     * 대화상자 객체 생성

     */

private AlertDialog createDialogBox(){

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle("안내");

builder.setMessage("종료하시겠습니까?");

builder.setIcon(R.drawable.alert_dialog_icon);


// 예 버튼 설정

builder.setPositiveButton("예", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton) {

msg = "예 버튼이 눌렀습니다. " + Integer.toString(whichButton);

txtMsg.setText(msg);

}

});


// 취소 버튼 설정

builder.setNeutralButton("취소",new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton) {

msg = "취소 버튼이 눌렸습니다. " + Integer.toString(whichButton);

txtMsg.setText(msg);

}

});


// 아니오 버튼 설정

builder.setNegativeButton("아니오", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int whichButton) {

msg = "아니오 버튼이 눌렸습니다. " + Integer.toString(whichButton);

txtMsg.setText(msg);

}

});

// 빌더 객체의 create() 메소드 호출하면 대화상자 객체 생성

AlertDialog dialog = builder.create();

return dialog;

}

getSharedPreferences myperf = getSharedPreferences("mypref",activity.mode_world.writeble);

SharedPreferences.editor myedit = mypref.edit();

mydedit.putstring("name",홍길동");

myedit.commit();

public class MainActivity extends Activity {

Button button3 ;

 

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

        button3 = (Button) findViewById(R.id.button3);

        // 버튼에 리스너 인터페이스를 할당 및 정의하여 설정한다.

        button3.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

            Toast.makeText(MainActivity.this, "토스트 알림 메시지", Toast.LENGTH_SHORT).show();

            button3.setVisibility(View.INVISIBLE);

           


            }

        });

}



리스트뷰 출력
    



   protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);                                
            SetContentView (Resource.Layout.Main);
            Button button = FindViewById<Button> (Resource.Id.myButton);
            ListView listview1 = FindViewById<ListView> (Resource.Id.listView1);

            button.Click += delegate {
            
            string[] items = new string[] { "Vegetables","Fruits","Flower Buds","Legumes","Bulbs","Tubers" };
                ArrayAdapter<String> ListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, items);
                listview1.Adapter = ListAdapter;
            };
        }

 


http://docs.xamarin.com/guides/android/user_interface/working_with_listviews_and_adapters/part_2_-_populating_a_listview_with_data