Questions tagged [setfocus]

For questions related to the SetFocus method, which moves the focus to the specified form or Window.

The SetFocus method moves the focus to the specified Form, the specified control on the Form/Window, or to the specified Window. You can use the SetFocus method when you want a particular field or control or Window to have the focus so that all user input is directed to this object.

430 questions
182
votes
16 answers

How do I put focus on a TextBox when a form loads?

I have a TextBox in my C# program. I need focus to be on this TextBox when the program starts. I tried this on Form_Load: MyTextBox.Focus(); but it doesn't work. How do I put focus on this when the form loads?
Gali
  • 14,511
  • 28
  • 80
  • 105
113
votes
6 answers

Set element focus in angular way

After looking for examples of how set focus elements with angular, I saw that most of them use some variable to watch for then set focus, and most of them use one different variable for each field they want to set focus. In a form, with a lot of…
Tiago
  • 1,735
  • 3
  • 14
  • 19
62
votes
8 answers

Setting focus to iframe contents

I have a page with a document.onkeydown event handler, and I'm loading it inside an iframe in another page. I have to click inside the iframe to get the content page to start "listening". Is there some way I can use JavaScript in the outer page to…
Jimmy
  • 89,068
  • 17
  • 119
  • 137
57
votes
7 answers

Correct way to focus an element in Selenium WebDriver using Java

What's the equivalent of selenium.focus() for WebDriver? element.sendKeys(""); or new Actions(driver).moveToElement(element).perform(); I have tried both of them and they worked, but which one would always work on all elements? Which one is the…
questions
  • 2,337
  • 4
  • 24
  • 39
47
votes
10 answers

Set focus on an input with Ionic 2

SOLVED : import { Component, ViewChild} from '@angular/core'; import { Keyboard } from 'ionic-native'; @Component({ templateUrl: 'build/pages/home/home.html' }) export class HomePage { @ViewChild('input') myInput ; constructor() {} …
Thomas
  • 1,509
  • 4
  • 15
  • 25
46
votes
7 answers

Set keyboard focus to a

I have the following code snippet:
webdad3
  • 8,893
  • 30
  • 121
  • 223
41
votes
9 answers

Set focus to field in dynamically loaded DIV

What is the proper method to set the focus to a specific field within a dynamically loaded DIV? $("#display").load("?control=msgs"); // loads the HTML into the DIV $('#display').fadeIn("fast"); // display it $("tex#header").focus(); // ??…
MrG
  • 5,277
  • 17
  • 48
  • 66
31
votes
10 answers

How to Set Focus on JTextField?

I make my game run without mouse so using pointer is not a choice. High Score menu will show when player lose. this is my code highScore=new MyTextField("Your Name"); highScore.addKeyListener(this); highScore.setFont(font); …
Kenjiro
  • 749
  • 1
  • 12
  • 33
31
votes
6 answers

KeyCode_Enter to next edittext

In edittext, after typing 'Enter' key, system make a new line inside it. I'd like to focus on next edittext, no new line. how to code? my code in xml is below
soclose
  • 2,773
  • 12
  • 51
  • 60
25
votes
2 answers

In Javascript setting a textarea with focus() does not work if called as a child window

I have a simple test page that sets the focus to a textarea on an oninit function. However the exact code fails to do this if the page is called as a child. Putting alert box proves that the oninit function is being called but fails to put the focus…
Ian Smith
  • 261
  • 1
  • 3
  • 5
22
votes
1 answer

How to Set the Initial Focus of the control in the particular window?

I created an application in which I use window procedure to keep track of all the controls in the window. My question is, how do I initially set the focus to the first created control in the window?
karthik
  • 17,453
  • 70
  • 78
  • 122
20
votes
10 answers

Set focus to textbox in ASP.NET Login control on page load

I am trying to set the focus to the user name TextBox which is inside an ASP.NET Login control. I have tried to do this a couple of ways but none seem to be working. The page is loading but not going to the control. Here is the code I've…
CodeFirstAndy
  • 591
  • 3
  • 8
  • 26
18
votes
1 answer

Tkinter set focus on Entry widget

Here is my code: import tkinter as tk userData = tk.Tk() nbdays = tk.IntVar() mainframe = tk.Frame(userData, relief= 'raised', borderwidth=1) tk.Label(mainframe, text = 'Number of days', font = 10).place(x=2, y = 30) tk.Entry(mainframe, width= 8,…
Cyrus TNZ63
  • 209
  • 1
  • 2
  • 6
16
votes
2 answers

Android WebView - Setting HTML Field focus using Javascript

I have an application with just a visible WebView component to it which is used to display some dynamically generated HTML (can run Javascript too). It's enabled for the WebView. For a few pages I am trying to set the focus of one of the input text…
Swaroop
  • 908
  • 1
  • 12
  • 25
16
votes
3 answers

Vue: How to call .focus() on button click

I only started coding with vue.js yesterday, and I don't know how to "focus" on a textbox without using the "traditional" JS way, which is document.getElementById('myTextBox').focus(). Initially, my textbox is hidden. I have a "Start" button, and…
ITWitch
  • 1,729
  • 5
  • 20
  • 38
1
2 3
28 29